I want to send a notification whenever the data in firebase changes.
But when I use addValueEvenListener()
method it returns more than once. After that I tried using addListenerForSingleValueEvent()
method but it now returns 2 times, When I start the app and when the data changes. Is there a way for it to return only one time which is when the data changes and not when the app starts?
Here is my code for now:
databaseReference.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot snapshot) {
sendNotification("notification","App name",getIntent().getStringExtra("storeid"));
}
@Override
public void onCancelled(@NonNull DatabaseError error) {
}
});
EDIT: Just so every one understand my question. When I start the app, a notification is sent because of the code above. And I don't want this to happen, Instead I need to only send the notification when the data changes.