0
Hello, I’m trying to read data in firebase and pass to an object, but when I used to use this object outside the onDataChange it showed the object data as null
So I made the following Log’s to test:
public void readDatas(){
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 when reading the Firebase data and passing to the object.
How could I solve this problem?
Thank you in advance
Classic problem of asynchrony
– Rosário Pereira Fernandes
Always put your code in text, avoid images for this
– Costamilam