I have an event listener attached to firebase. But the event listener is called twice on a datachange. I feel that I am not removing the listener properly. Can someone please guide here is my code:
I have the listener inside onStart() as follows
ref5 = appRef.orderByChild("*****").equalTo(*****)
listenerApp = ref5.addValueEventListener(object: ValueEventListener {
override fun onCancelled(p0: DatabaseError) {
Toast.makeText(this,"Error", Toast.LENGTH_LONG).show()
}
override fun onDataChange(p0: DataSnapshot) {
// Do Something
}
})
The listener is detached as follows inside onStop()
if((this::listenerApp.isInitialized)&&(this::ref5.isInitialized)) ref5.removeEventListener(listenerApp)
Where am I getting wrong?
One more thing is that the listener is not always evoked twice. It happens occasionally