Problem with Data Reading in Firebase

0

Hello, I am trying to read data in firebase and pass to an object, but when I used this object outside onDataChange it showed the object data as null

So I did the following Log's to test:

publicvoidreadDatas(){valueEventListener=ref.child("users").child(userId).addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
            user = dataSnapshot.getValue(User.class);
            Log.i("test", "id 1 "+user.getCurrentCharacter());

        }

        @Override
        public void onCancelled(@NonNull DatabaseError databaseError) {

        }
    });
    Log.i("test", "id 2 "+user.getCurrentCharacter());
}

And it seems that this happened because it has a delay in reading the Firebase data and passing it to the object.

How could I solve this problem?

Thank you in advance

    
asked by anonymous 22.08.2018 / 06:39

0 answers