0

i´m trying to get data from my firebase database when a user log in successfully, but i can´t do it with the code that I have, let me paste you my code:

login class:

AdminFirebase.loadAdmin(task.getResult().getUser());

AdminFirebase class:

private static DatabaseReference adminRef= ref.child("Administradores");

public static void loadAdmin(FirebaseUser user){

    DatabaseReference userRef=adminRef.child(user.getUid());
    userRef.addListenerForSingleValueEvent(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            Administrador administrador=dataSnapshot.getValue(Administrador.class);
            Sesion.admin=administrador;
        }
        @Override
        public void onCancelled(DatabaseError databaseError) {

        }

});

I already debug my code and when the code its on the userRef.addListener as you can see on the image, all the data its according with the database, but when I try to execute the next code it skip until the finish of the method,so it seems that something its wrong on that line, could somebody help me with this?

https://i.stack.imgur.com/gOf98.png

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • `ValueEventListener`s and `ChildEventListener`s are executed asynchronously. The lines in your function only starts another thread of execution that will __eventually__ call `onDataChange`. They won't get executed immediately. – Sunshinator Jan 18 '17 at 17:11
  • thanks a lot mate i didnt know that, its working as expected – Gaston de la cruz Jan 18 '17 at 17:36

0 Answers0