androidfirebasefirebase-realtime-database

Is ValueEventListener keep listening if the reference it was listening to is being removed?


I have this code:

FirebaseDatabase.reference.child(path).addValueEventListener(object : ValueEventListener 
{
        override fun onDataChange(snapshot: DataSnapshot) {
            /**LOGIC**/
        }
        override fun onCancelled(error: DatabaseError) {

        }
    })

While path removed from database.

Is it still listening?


Solution

  • A listener always listens to changes regardless of whether or not there is any data at the given location. It will keep listening until the program terminates or you remove the listener. If there was no data present at the time of registration, then new data appears, then it will trigger the listener callbacks.