Integer scores[] = new Integer[10];
int count = 0;
I have some data that I want to put into array
. I put it in onChildAdded, but if I need to get the data from the array out of the onChildAdded, console shows "null".
If I will try to get the data of array into onChildAdded, it will be success
data.child("scores").addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
count++;
scores[count] = dataSnapshot.getValue(Integer.class);
}
@Override
public void onChildChanged(DataSnapshot dataSnapshot, String s) {
}
@Override
public void onChildRemoved(DataSnapshot dataSnapshot) {
}
@Override
public void onChildMoved(DataSnapshot dataSnapshot, String s) {
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
int i = scores[1];
IMPORTANT MOMENT
For example, If I will use operation FOR
for (int i = 0; i < 10; ++i) {
scores[i] = i;
}
int i = scores[3];
i will not be null