The I have created a document reference to get the document and save in in an object of a model class. then i am trying to get back the value in the return statement. But it displays Null.
public class UserRetriver {
FirebaseAuth fAuth;
FirebaseFirestore fStore;
User_model um=new User_model();
public UserRetriver() {
fAuth=FirebaseAuth.getInstance();
fStore=FirebaseFirestore.getInstance();
}
public String getDisplayName(String UserID)
{ Log.d("UR123","Function was run");
DocumentReference Dr=fStore.collection("users").document(UserID);
Dr.get().addOnSuccessListener(new OnSuccessListener<DocumentSnapshot>() {
@Override
public void onSuccess(DocumentSnapshot documentSnapshot) {
um=documentSnapshot.toObject(User_model.class);
Log.d("UR123", "From Listener: "+um.getdName());
}
});
String DName=um.getdName();
Log.d("UR123","From End Of Function " +DName);
return DName;
} }
I thinking I am messing up the scope of the Object somewhere. Here Is the Logcat Output