Answer the question
In order to leave comments, you need to log in
Strange behavior of method for getting data from Firebase collection. How to fix?
Why is the method for getting data from the collection misbehaving?
public List<Note> loadNotes(){
database.collection(NoteCollection.COLLECTION_NAME)
.get()
.addOnSuccessListener(queryDocumentSnapshots -> {
notes.addAll(queryDocumentSnapshots.toObjects(Note.class));
Log.d("loadingNote", String.valueOf(notes.size()));
})
.addOnFailureListener(e -> {
Log.d("loadingNote", e.toString());
});
Log.d("loadingNote", String.valueOf(notes.size()));
return notes;
}
2019-02-26 07:42:04.194 12548-12548/com.rafalsky.firebaselesson1 D/loadingNote:
0
Answer the question
In order to leave comments, you need to log in
Well, even the logs show everything.
This is an asynchronous operation, the addOnSuccessListener callback is called after your method has exited.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question