I'm gettig a error that my variable inside the Listener display the correct value, but when it leaves it's just an empty variable.
if (i.getStringExtra("where").equals("login")){
email = i.getStringExtra("email");
db.collection("users").whereEqualTo("email", email).get()
.addOnCompleteListener(task -> {
if (task.isSuccessful()) {
for (DocumentSnapshot document : task.getResult()) {
name = document.getString("name");
Log.d("username", name);
}
}
});
}else{
//anything
}
Log.d("username", name);
userName.setText(name);
The Log inside of the Listener returns the correct value, and the outsider giver a null pointer excpetion println needs a message. Tried to use this.name instead of just name, still did not work.
UPDATE
i give the variable name a value before enter the if condition, and notice that the Log.d that is outside of the if prints first the older value, and then the Log.d that is inside if prints the correct value:
2021-02-05 13:29:06.791 27900-27900/com.example.pomodorotasks D/username: teste
2021-02-05 13:29:09.020 27900-27900/com.example.pomodorotasks D/username: Rafael Alves
"teste" older value "Rafael Alves" the value that name receive inside of listener
It seems that it take a time to the listener do what it need to do, i don't know.