0
I’m having trouble working with asynchronous Firebase Database data
I need to identify the type of logged-in user:
public Static String getTipoUsuario(){ User = query User(); Return usuario.getType(); }
public static Usuario consultarUsuario(){
DatabaseReference firebaseRef = ConfiguracaoFirebase.getFirebase();
DatabaseReference usuario = firebaseRef.child("usuarios").child(getIdUsuario());
usuario.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if (dataSnapshot.exists()){
usuarioLogado = dataSnapshot.getValue(Usuario.class);
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
System.out.println("The read failed: " + databaseError.getCode());
}
});
return usuarioLogado;
}
What happens is that the method always returns NULL, because the application executes the code before the return of the database information.
How can I make it return only with the certainty that the query has been made ?
Where you are creating this user variableLog?
– Germano Buss Niehues
Global variable of a user class
– BRUNO MAYER