Below is the code I used to retrieve documents data in a recyclerview. It works fine. But whenever the new document is added, it does not update it in real time. I know snapshot listener is for that purpose only but having a hard time to get it work. Any help will be appreciated. :)
mFirestore.collection("Users").get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
@Override
public void onComplete(@NonNull Task<QuerySnapshot> task) {
if (task.isSuccessful()){
for (DocumentSnapshot document : task.getResult()) {
Message message = document.toObject(Message.class);
messageList.add(message);
mAdapter.notifyDataSetChanged();
}
}
}
});
If you want to keep listening your Firestore data (realtime update), you should do like this:
the way you use only retrieve Firestore data once.
Check this >> https://firebase.google.com/docs/firestore/query-data/listen
you should separate the snapshot event like this.. then you can easily find out, what's the problem
Maybe the snapshot you got, was triggered by [MODIFIED] event, not [ADDED]..
Please see how to use it in recycler view: