I am quite new to Java and firestore, been trying to do a query out of an array of Ids, below are my code snippet
private void flagCustomer (ArrayList<String> historyList, long time, String originalId){
DocumentReference historyRef;
int completeCount = 0;
for(int i = 0; i < historyList.size(); i++){
historyRef = fStore.collection("history").document(historyList.get(i));
historyRef.get().addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() {
@Override
public void onComplete(@NonNull Task<DocumentSnapshot> task) {
if (task.isSuccessful()) {
DocumentSnapshot document = task.getResult();
if (document.exists()) {
//do something...
} else {
Log.d("success", "No such document");
}
} else {
Log.w("failed", "get failed with ", task.getException());
}
}
});
}
}
Basically i had an array of historyList
which contain something like [id1,id2,id3]
and I wanted to retrieve specific data in my firestore using these ids.
The problem is that the program always end the loop before the query is complete, is there any way to make the program wait for my query to finish or is there any better way to do the query instead of not putting it in a loop?