So i have the email of all the acconts, that exists in my firestore users ("Registos") collection in a spinner, and whenever i click the email i want, i need to get the uid, So i wanted to create a function that returns the uid by email whenever i need to. Here is what i have :
public String GetId(String email) {
String Id = "";
mFirestore.collection("Registos")
.whereEqualTo("Email", email)
.get()
.addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
@Override
public void onComplete(@NonNull Task<QuerySnapshot> task) {
if (task.isSuccessful()) {
for (QueryDocumentSnapshot document : task.getResult()) {
Id = (document.getId());
getUserID(Id);
Log.d("TAG1", "Id " + userID);
Log.d("TAG2", document.getId() + " => " + document.getData());
}
} else {
Log.d("TAG3", "Error getting documents: ", task.getException());
}
}
});
return Id;
}
So first i get an error in Id inside the for loop : Variable 'Id' is accessed from within inner class, needs to be final or effectively final
And even if i make the suggested changes, this function allways return null instead of returning the value that "document.getId()" gets, which is correct.