Firebase in Data Change is called multiple times in add event event
I have set up two listeners
- Request to get the last message
- If the last message is a group type, I get the group information using the group Listener
However, when I get the message type using messageListener and set the groupListener, it returns multiple onDataChange
Debug.e("parentsnap",dataSnapshot.getValue().toString());
called more than once How do I do this please send
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);
+3
source to share