Right now I have working code to grab a DocumentReference from a Firestore database by id. I'm trying to then perform a .get() command to process a particular field from the Document and nothing is happening. Here's my code:
FirebaseFirestore mFirestore = FirebaseFirestore.getInstance();
DocumentReference docRef = mFirestore.collection(collection).document(doc_key);
Log.d("LOGGER", "docRefID is:" + docRef.getId());
docRef.get().addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() {
@Override
public void onComplete(@NonNull Task<DocumentSnapshot> task) {
Log.d("LOGGER", "task complete"); // this is never being called
if (task.isSuccessful()) {
DocumentSnapshot document = task.getResult();
if (document != null) {
Log.d("LOGGER", "Got in here");
foo(document.getString(myField)); // this is where I'm trying to do things, but its not getting here
} else {
Log.d("LOGGER", "No such document");
}
} else {
Log.d("LOGGER", "get failed with ", task.getException());
}
}
});
while( // foo has not been called yet ) {
Log.d("LOGGER", "still waiting");
Thread.sleep(2000);
}
Here's my logcat output:
2020-04-13 13:55:47.449 24669-24669/com.example.myurbanflix D/LOGGER: docRefID is:nNuztOjrN0kz53XTmCS1
2020-04-13 13:55:47.450 24669-24669/com.example.myurbanflix D/LOGGER: still waiting
2020-04-13 13:55:49.452 24669-24669/com.example.myurbanflix D/LOGGER: still waiting
2020-04-13 13:55:51.452 24669-24669/com.example.myurbanflix D/LOGGER: still waiting
When I run the program, I am properly seeing my DocumentReference's ID and it IS the value of the ID of the document I'm trying to query, but NONE of the other Log messages are appearing. It seems like the task is never completing because none of those inner Log messages are appearing and my while loop at the bottom just keeps pinging logcat every two seconds. I should also note for context I am trying to do this inside a FirestoreAdapter for use in a RecyclerView. Any idea what I'm doing wrong?