I have set two listeners
However, when I get the type from the message using messageListener and set groupListener it returns multiple onDataChange
Debug.e("parentsnap",dataSnapshot.getValue().toString());
gets called more than one times
How should I do it, please guide
groupListener = new ValueEventListener() {
@SuppressWarnings("unchecked")
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
Debug.e("parent snap", dataSnapshot.getValue().toString());
for (DataSnapshot d :
dataSnapshot.getChildren()) {
//my code
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
};
groups.child(chatId).addValueEventListener(groupListener);
If you need to receive data one time you need to use addListenerForSingleValueEvent(...)
instead of
addValueEventListener(...)
. Then onDataChange()
will return only one time
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With