我想从Firebase Firestore快照返回数据(ArrayList)。我如何进行操作,因为Firebase方法不允许我向onEventListener添加任何返回类型。
public void getLiveChatMessages() {
db.collection("users")
.document(onboardingFirebaseUser.returnCurrentUserId())
.collection("conversations")
.document("conversation0") //Specified conversation
.collection("messages")
.addSnapshotListener(new EventListener<QuerySnapshot>() {
@Override
public void onEvent(@Nullable QuerySnapshot value,
@Nullable FirebaseFirestoreException e) {
if (e != null) {
Log.w(TAG, "Listen failed.", e);
return;
}
List<String> messages = new ArrayList<>();
for (QueryDocumentSnapshot doc : value) {
if (doc.get("message") != null) {
messages.add(doc.getString("message"));
}
}
Log.d(TAG, "Message: " + messages);
return messages; //this is my goal
}
});
}
在此先感谢您的帮助!