Retrieving data from Firebase DB and storing in local variable: Android -
my app stores user location data in firebase realtime database
. intend retrieve of data , process within app. able fetch desired data firebase db (checked through debugging). want store data in local variables. able store values except 1 value (debugger shows value null, though present in datasnapshot
.). data firebase in userdatalocation
object form , following class same:
userdatalocation
class:
public class userlocationdata { string mobile, name, latitude, longitude, proximity, connection_limit, last_updated; public userlocationdata() { } public userlocationdata(string mobile, string name, string latitude, string longitude, string proximity, string connection_limit, string last_updated) { this.mobile = mobile; this.name = name; this.latitude = latitude; this.longitude = longitude; this.proximity = proximity; this.connection_limit = connection_limit; this.last_updated = last_updated; } public string getmobile() { return mobile; } public void setmobile(string mobile) { this.mobile = mobile; } public string getname() { return name; } public void setname(string name) { this.name = name; } public string getlatitude() { return latitude; } public void setlatitude(string latitude) { this.latitude = latitude; } public string getlongitude() { return longitude; } public void setlongitude(string longitude) { this.longitude = longitude; } public string getproximity() { return proximity; } public void setproximity(string proximity) { this.proximity = proximity; } public string getconnection_limit() { return connection_limit; } public void setconnection_limit(string connection_limit) { this.connection_limit = connection_limit; } public string getlast_updated() { return last_updated; } public void setlast_updated(string last_updated) { this.last_updated = last_updated; } }
here how retrieving , storing data:
@override public void ondatachange(datasnapshot datasnapshot) { (datasnapshot child : datasnapshot.getchildren()) { userlocationdata = child.getvalue(userlocationdata.class); string connectionkey = child.getkey(); if (!connectionkey.equals(currentusermobile)) { (int count = 0; count <= integer.parseint(connections_limit); count++) { **string last_updated = userlocationdata.last_updated;** //this showing null in debugger location connectionlocation = getlocationfromlatlng(userlocationdata.latitude, userlocationdata.longitude); {......} } } } } }
all variable except string last_updated = userlocationdata.last_updated;
having value.
can me resolve this???
i have resolved problem. error petty significant. actually, using last updated
key store last updated time. problem format of key. should have been last_updated
or else seems firebase db considers keys spaces
invalid. so, changed key last_updated
, problem solved.
hope helps someone.
Comments
Post a Comment