I am using Cloud Firestore in a separate thread in my Android app, so I don't want to use listeners OnSuccessListener
and OnFailureListener
to run in yet another thread. Can I just make my thread wait for the result (and catch any exceptions if needed)?
Currently the code for querying is something like this:
FirebaseFirestore.getInstance().collection("someCollection").get().addOnSuccessListener(new OnSuccessListener<QuerySnapshot>() {
@Override
public void onSuccess(QuerySnapshot documentSnapshots) {
// do something on the UI thread with the retrieved data
}
});
What I'd like to have:
FirebaseFirestore.getInstance().collection("someCollection").getAndWaitForResult();
//Block the thread and wait for result, no callbacks.
//getAndWaitForResult() is not a real function, just something to describe my intention.
I used to work with Parse Server before, and it was quite trivial there.