In my app, I have an id that is supposed to be pulled down from firebase real time database. If I pull it down and it sees there is not an id available, then it sets the id
I had kinda the same problem of getting an object out of FireBase Realtime Database, and as @Lewis McGeary wrote, I Just made my program Wait until all the data gets retrived from the Database
Here's my sample code:
BarReference = FirebaseDatabase.getInstance().getReference("Users").child(myUID);
ValueEventListener UserChangeListener = new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
me = dataSnapshot.getValue(UserDataSet.class);
}
@Override
public void onCancelled(DatabaseError databaseError) {
Log.w(TAG, "loadPost:onCancelled", databaseError.toException());
}
};
BarReference.addValueEventListener(UserChangeListener);
while (me == null){
Log.w(TAG, "Waiting For The Data to Download");
progresBar.setVisibility(View.VISIBLE);
return;
}
Hope that Helps! (^_^)