As the title says, I want to know the difference between addValueEventListener()
and addListenerForSingleValueEvent()
of Firebase.
addValueEventListener() keep listening to query or database reference it is attached to. But addListenerForSingleValueEvent() executes onDataChange method immediately and after executing that method once, it stops listening to the reference location it is attached to.
public interface ValueEventListener. Classes implementing this interface can be used to receive events about data changes at a location. Attach the listener to a location user addValueEventListener(ValueEventListener) .
firebase. database. DataSnapshot. A DataSnapshot contains data from a Database location. Any time you read data from the Database, you receive the data as a DataSnapshot .
public interface ChildEventListener. Classes implementing this interface can be used to receive events about changes in the child locations of a given DatabaseReference ref. Attach the listener to a location using addChildEventListener(ChildEventListener) and the appropriate method will be triggered when changes occur.
addValueEventListener()
keep listening to query or database reference it is attached to.
But addListenerForSingleValueEvent()
executes onDataChange
method immediately and after executing that method once, it stops listening to the reference location it is attached to.
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