I have created an Intent service, and in it, I have created a listener, but as addValueEventListener get called three-time
- first when declared
- when data is added
- when data is removed
How can I modified it so that I can have events only when the data is added
public class MyIntentServiceForEmploy extends IntentService { public MyIntentServiceForEmploy() { super("MyIntentServiceForEmploy"); } @Override protected void onHandleIntent(Intent intent) { DatabaseReference reference = firebase.getAllOnlineOrder(); reference.addValueEventListener(new ValueEventListener() { @Override public void onDataChange(@NonNull DataSnapshot snapshot) { Toast.makeText(MyIntentServiceForEmploy.this, "notiifiicatiion", Toast.LENGTH_SHORT).show(); } @Override public void onCancelled(@NonNull DatabaseError error) { } }); } }
ValueEventListenerworks like this only . There is aChildEventListeneryou might need this one .