title: How to get notifications of newly added data in firestore android studio?
body: <p>I am doing a notification on my app and I am using firestore. My problem is I want to send a notification to the user when the <code>snapshotlistener</code> detect a newly added data to the database But when I open the app it will show the existing notification right away even though i did not added a new data. I need some conditions where I can only get the newly added data or if there's something lacking in my database data that will need in order to overcome this issue. Below is my databse structure.<a href="https://i.stack.imgur.com/F1XUL.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/F1XUL.png" alt="enter image description here"></a></p>
  
  <pre><code>db.collection("Buyers")
                  .document(userID)
                  .collection("Notifications")
                  .addSnapshotListener(new EventListener&lt;QuerySnapshot&gt;() {
                      @Override
                      public void onEvent(@Nullable QuerySnapshot snapshots, @Nullable FirebaseFirestoreException e) {
                          if (e != null) {
                              Log.e(LOG_DB, e.toString());
                              return;
                          }
                          for (DocumentChange dc : snapshots.getDocumentChanges()) {
  
                              if (dc.getType() == DocumentChange.Type.ADDED) {
                                  String title = dc.getDocument().getData().get("notificationTitle").toString();
                                  String body = dc.getDocument().getData().get("notificationBody").toString();
  
                                  //Method to set Notifications
                                  getNotification(title, body);
                              }
                          }
                      }
                  });
  </code></pre>