Unable To Retrieve The Value From Firebase Database
I am trying to retrieve values from my firebase database. It is displaying the values in onDataChange() function but unable to display the values out of it . Code: public Records r
Solution 1:
As I mentioned in my comment call to Firebase is asynchronous. If you want your method to return Records
object you should use callback:
public void readtraditional(String email, MyCallback callback)
{
final Records record = new Records();
final String[] name = new String[1];
myRef.child(email).child("name").addValueEventListener(new
ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
name[0] = dataSnapshot.getValue().toString() ;
record.setName(name[0]);
callback.onSuccess(record)
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
Interface:
public interface MyCallback{
void onSuccess(Records record)
}
And you can call this method like this:
readtraditional(mystring,new MyCallback{
@Override
void onSuccess(Records record){
//do whatever you want
}
});
Post a Comment for "Unable To Retrieve The Value From Firebase Database"