When a user checks their friends list in my application, I want the application to go through each user in the list and retrieve their updated information from Cloud Firestore
.
This is my current code:
final CollectionReference usersRef= FirebaseFirestore.getInstance().collection("users");
usersRef.document(loggedEmail).collection("friends_list").get().addOnSuccessListener(new OnSuccessListener<QuerySnapshot>() {
@Override
public void onSuccess(QuerySnapshot documentSnapshots) {
if (!documentSnapshots.isEmpty()){
for (DocumentSnapshot friendDocument: documentSnapshots) {
usersRef.document(friendDocument.getString("email")).get().addOnSuccessListener
(new OnSuccessListener<DocumentSnapshot>() {
@Override
public void onSuccess(DocumentSnapshot documentSnapshot) {
User friend=documentSnapshot.toObject(User.class);
friendsList_UserList.add(friend);
}
});
}
}
else
noFriendsFound();
}
And this is an illustration of my desired process:

As you can see, I can get each user's information in this way, but I can’t find a way to listen to this process and continue when I have information about all the friends in the user list.
Is there a way that I can immediately get all the information about friends?
source
share