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
Your can do something like this on the main thread...
YourObject yourObject = (YourObject)new RunInBackground().
execute("someCollection","someDocument").get()
And the background thread is...
public class RunInBackground extends AsyncTask {
@Override
protected Object doInBackground(Object[] objects) {
Task documentSnapshotTask = FirebaseFirestore.getInstance().
collection((String) objects[0]).document((String) objects[1]).get();
YourObject obj=null;
try {
DocumentSnapshot documentSnapshot = Tasks.await(documentSnapshotTask);
obj = new YourObject();
obj.setter(documentSnapshot.get("your field"));
} catch (ExecutionException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
return obj;
}
}