What is the difference between the ChildEventListener and ValueEventListener Firebase interfaces?

The documentation says they both listen for changes in the location of the Firebase database.

+7
android firebase firebase-database
source share
2 answers

They do almost the same thing, although ChildEventListener can sometimes be more flexible: ChildEventListener you can specify different behavior for 4 actions ( onChildAdded , onChildChanged , onChildMoved and onChildRemoved ), and ValueEventListener provides only onDataChanged .

Also, the ChildEventListener provides DataSnapshots (immutable copies of the data) at the child location, and the ValueEventListener provides the DataSnapshot of the whole node.

+8
source share

The ValueEventListener is only triggered when this value changes, but the ChildEventListener listens not only for the value of this node, but also for all child nodes of the tree. Say you have a node that has one child. The ValueEventListener will be triggered when this node changes, but the ChildEventListener will also be triggered when the child values ​​are also changed. The documentation says that you should use the ChildEventListener with caution - it can be run many times.

+5
source share

All Articles