1

I'm listening for the last document in my collection. If a most recent document is added or changed, the listener is executed. However, it's executed also when it is attached (in other words, when the app starts). This behavior doesn't fit my needs: I'd want to execute the listener if, and only if, a most recent document is added or changed, but not as soon as the listener is attached.

You can find my code here:

    new SetupFirebaseFirestore(new SetupFirebaseFirestorePostExecuteCallback() {
        @Override
        public void onTaskCompleted(final FirebaseFirestore db) {

            db.collection("announcements").orderBy("timestamp", Query.Direction.DESCENDING).limit(1).addSnapshotListener(new EventListener<QuerySnapshot>() {
                @Override
                public void onEvent(@Nullable QuerySnapshot queryDocumentSnapshots, @Nullable FirebaseFirestoreException e) {
                    System.out.println("test"); [...]
                }
            });

        }
    }).execute();

Is it possible to do it without adding myself some fields in the document?

JarsOfJam-Scheduler
  • 2,809
  • 3
  • 31
  • 70
  • Sorry for this question. It has already been answered here: https://stackoverflow.com/questions/52955433/can-cloud-firestore-onsnapshot-only-trigger-on-changes-and-not-get-the-initia . – JarsOfJam-Scheduler Feb 02 '19 at 14:22

0 Answers0