I need to return the value that is retrieved from the document snapshot. I can see the correct value in the LOG but since it is out of scope, and only in onComplete, I cannot access it.
Can you please help?
public String getCoEmail() {
coUserReference = db.collection("users").document(email);
coUserReference.get().addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() {
@Override
public void onComplete(@NonNull Task<DocumentSnapshot> task) {
if (task.isSuccessful()) {
DocumentSnapshot document = task.getResult();
if (document.exists()) {
String coEmail = document.getString("coEmail");
Log.d(TAG, "DocumentSnapshot data: " + document.getString("coEmail"));
} else {
Log.d(TAG, "No such document");
}
} else {
Log.d(TAG, "get failed with ", task.getException());
}
}
});
return coEmail;
}