Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between addValueEventListener() and addListenerForSingleValueEvent() of firebase

Tags:

As the title says, I want to know the difference between addValueEventListener() and addListenerForSingleValueEvent() of Firebase.

like image 728
Mehdi Glida Avatar asked Jan 10 '17 21:01

Mehdi Glida


People also ask

What is the difference between addValueEventListener and addListenerForSingleValueEvent?

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.

What is addValueEventListener in firebase?

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) .

What is snapshot in firebase?

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 .

What is addChildEventListener?

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.


1 Answers

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.

like image 183
Mohammed Junaid Avatar answered Oct 10 '22 18:10

Mohammed Junaid