Reputation: 1003
I'm a beginner in Firebase and I'm still learning so I made an login-signup app and I'm adding more functionality like Saving Data(which is done) and now I can't figure out how I will retrieve multiple data with different User UID's
Heres a screenshot of my database
I would like to retrieve all of the data here in 3 different edittext in the layout basically when a person logs in, the program should read database and check if there is data in there then it will get data from the database otherwise it will show a toast saying that No data saved to retrieve... I would be really thankfull if anyone helps me out with this...
Upvotes: 2
Views: 3758
Reputation: 422
You need to register callacks for Firebase data.
DatabaseReference ref = FirebaseDatabase.getInstance().getReferenceFromUrl("<your-firebase-app-url>").child("<node-name-to-observe>");
ref.addChildEventListener(new ChildEventListener(){
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
// save to sqlite
}
@Override
public void onChildChanged(DataSnapshot dataSnapshot, String s) {
}
@Override
public void onChildRemoved(DataSnapshot dataSnapshot) {
}
});
This is a async call. You need to save it to local db like Sqlite and use it from there. Callbacks of ChildEventListener will be called multiple times based on number of child nodes present.
Upvotes: 1