In my application I need to retrieve a value from one node in my database and use this value to pass in to another method elsewhere in my code.
Is it possible to read data from the data snapshot in firebase and return this value for use outside of the data snapshot?
For example, to return the phoneNum or groupId variables from the below method for use in another method:
public void getUserPhoneNum(String uId){
usersDatabase.child(uId).addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if (dataSnapshot.exists() || dataSnapshot.getValue() != null) {
User mUser = dataSnapshot.getValue(User.class);
String userPhone = mUser.getPhoneNum();
Group mGroup = dataSnapshot.child("groups").getValue(Group.class);
String groupId = mGroup.getGroupId();
groupsDatabase.child(groupId).child("members").child(userPhone).child("playing").setValue()
if (userPhone != null) {
}
}
else {
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}