Skip to content Skip to sidebar Skip to footer

How To Get Data From Real-time Database In Firebase

I've used the Real-Time Database with this setup: ->users ->uid ->name ->email ->other info If I wanted to save the user data I would us

Solution 1:

Firebase uses listeners to get data. That is just the nature of how it works. Although, you can use a single event listener (the equivalent of just grabbing the data once). It will fire immediately and get the data, and will not fire ever again. Here's a code example to get the current user's email:

//Get User ID
final String userId = getUid();

//Single event listener
mDatabase.child("users").child(userId).addListenerForSingleValueEvent(
    new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            // Get user value
            User user = dataSnapshot.getValue(User.class);

            //user.email now has your email value
        }
    });

Post a Comment for "How To Get Data From Real-time Database In Firebase"