John John - 1 year ago 80
Android Question

Retrieve all data under Uid Firebase Android

Hello guys I am new to Firebase and I am trying to retrieve all data under Uid.
I store them like this:

//some other code here
DatabaseReference newProduct =mDatabase.child(category).child("Product").push();

My question is how can I retrieve all data under userUid category? Do I need something like

Answer Source

What you need to do is use a listener to retrieve that data, something along the lines of

 mDatabase.child(category).child("Product").addValueEventListener(new ValueEventListener() {
                public void onDataChange(DataSnapshot dataSnapshot) {
                 String name = (String) dataSnapshot.child("productname").getValue;
                 String date = (String) dataSnapshot.child("date").getValue;


                public void onCancelled(DatabaseError databaseError) {


There you go, now you pulled all that data as Strings.

Also, I would suggest that instead of



String uid = (String) auth.getCurrentUser().getUid();

and just put uid in there instead, that way your code is much cleaner and everytime you need to refer to uid, you have a string for it.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download