I am developing the home of my Social Network; so, to view the posts of the following users I have to insert all the following users on an array list. The following variables are declared globally:
private ArrayList<String> Uidrecord = new ArrayList<>();
private ArrayList<String> uidFollowing = new ArrayList<>();
I'm doing it like this: (This is on the oncreate)
FirebaseFirestore.getInstance().collection("following").document(FirebaseAuth.getInstance().getCurrentUser().getUid()).collection("userFollowing").get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
@Override
public void onComplete(@NonNull Task<QuerySnapshot> task) {
if (task.isSuccessful()) {
for (QueryDocumentSnapshot document : task.getResult()) {
document.getData();
Uidrecord.add(cont,String.valueOf(document.getData()));
cont++;
}
int conta = 0;
for (String item: Uidrecord){
if(item == null) {
Toast.makeText(MainActivity.this, "null item", Toast.LENGTH_SHORT).show();
break;
}
uidFollowing.add(conta, item);
//Toast.makeText(MainActivity.this, uidFollowing.get(conta), Toast.LENGTH_SHORT).show();
conta++;
}
Toast.makeText(MainActivity.this, uidFollowing.size() + "", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(MainActivity.this, task.getException().toString(), Toast.LENGTH_SHORT).show();
}
}
});
the problem is that when I go to do (outside the addOnCompleteListener method but always in the oncreate):
uidFollowing.get(0)
the returned value is null.
Do you know how I could solve this problem?