I think you are doing your request wrong. onChildAdded
method returns you every child of a certain value (userID2, I suppose). If this is what you want, just use onValueEventListener()
to retrieve the entire dataSnapshot of your userId2 node every time it changes.
If you want to retrieve data only once, you should use onSingleValueEventListener()
. And OnChildEvent()
used to retrieve data lists where you want to track each child separately. For example, if you attach OnChildEventListener
to mReference.child(rID)
, you will get onChildAdded
for each userId, which is very useful, for example, fill in the RecyclerView
or ListView
to update each element separately with your Firebase data.
If I'm not mistaken, you just get updates to your userId2
link, in this case attach OnValueEventListener
to this link, and you will get a call every time the value is changed, deleted or added.
firebaseDatabaseRef.addValueEventListener(new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { customPOJO customPOJO = dataSnapshot.getValue(YourCustomPOJO.class); customPOJO.getName(); customPOJO.getEmail(); customPOJO.getfavoriteFood();
source share