The documentation says they both listen to changes at a Firebase database location.
these are the key differences between the two
if your database has following records:
-LDU4T1buanVuJrpOYxW
message:"hi stack"
user: "john"
-LDasdfa1buanVuJrpOYxW
message:"hi john"
user: "stack"
1) on new entry:
2) because of a) getting the new record in childeventlistener is
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
Map map =(Map) dataSnapshot.getValue();
String message = map.get("message").toString();
because of b) getting the new record in ValueEventListener is
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot data : dataSnapshot.getChildren()) {
.... loop until end
Map map = (Map)data.getValue();
String message = map.get("message").toString();
so for example if you don't care what happen when somebody delete the first in ValueEventListener you always get notified but in ChildEventListener you only get notified if you override onChildRemoved.
so it depends on what you want to do. for example in a chat app. you will only care about new messages, you don't want to be reinserting all messages again in your chat room.