I have little experience with the firebase database. The following code doesn't work it as it doesn't retrieve the name of the user from the database. However, it shows the datasnapshot
from the firebase. Here is the code.
databaseReference = FirebaseDatabase.getInstance().getReference().child("/userList/"+ FirebaseAuth.getInstance().getUid());
databaseReference.addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(@NonNull DataSnapshot dataSnapshot, @Nullable String s) {
Log.d(TAG, "onChildAdded: " + dataSnapshot.toString());
for (DataSnapshot dataSnapshot1 : dataSnapshot.getChildren()){
Users users = dataSnapshot1.getValue(Users.class);
String firstName = users.getFirstName();
String lastName = users.getLastName();
Log.d(TAG, "onChildAdded: " + firstName + " " + lastName);
}
}
}
The datasnapshot
from firebase
onChildAdded: DataSnapshot {
key = -Lt_5ltPuMx6CPSk5X8-,
value = {
firstName=firstname,
lastName=lastname,
email=firstname@gmail.com
}
}
Here's how I store the firebase data.