I have an issue with the get method for my FireStore database.
The issue is on the line where it says:
returnUser = documentSnapshot.toObject(User.class);
It is assigning returnUser inside the inner class, but it's not assigning it to the global returnUser.
How can I make it so that my method returns a User object?
I can not change the inner class return type.
//Globally Declared
private User returnUser;
public User getUser(String id) {
DocumentReference docRef = db.collection(COLLECTION_PATH).document(id);
docRef.get()
.addOnSuccessListener(new OnSuccessListener<DocumentSnapshot>() {
@Override
public void onSuccess(DocumentSnapshot documentSnapshot) {
if (documentSnapshot.exists()) {
//returnUser has value assigned here.
returnUser = documentSnapshot.toObject(User.class);
Log.d(TAG, "Document Does Exist!!");
} else {
Log.d(TAG, "Document Does Not Exist");
}
}
});
//returnUser is null because the inner class did not assign it a value
return returnUser;
}