Athul Antony NP Athul Antony NP - 14 days ago 5
Android Question

Firebase retrieving the child value from realtime database of Firebase

I am new to Firebase and Android. I have stored user authentication details (name, profile image other than email ID) in my Firebase account. I want to retrieve those data (such as names etc.,) to the other part of my app. How can I retrieve my realtime database child values?

enter image description here

Answer
final FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference ref = database.getReference("userID").child("displayName");

// Attach a listener to read the data at our posts reference
ref.addValueEventListener(new ValueEventListener() {
    @Override
    public void onDataChange(DataSnapshot dataSnapshot) {
        String displayName = dataSnapshot.getValue().toString();
        System.out.println(displayName );
    }

For more: Read and Write Data on Android - Firebase Documentation