I know that the documentation says "// In Java, each listener must be removed explicitly.". But there is a problem.
I deploy my app - add a listener (save pointer). But when I re-deploy my app the listener is still there, but I cannot remove it because I don´t have a pointer for it.
So is any way how to remove all listeners? (without server restart)
Detach listeners Callbacks are removed by calling the removeEventListener() method on your Firebase database reference. If a listener has been added multiple times to a data location, it is called multiple times for each event, and you must detach it the same number of times to remove it completely.
Detach listeners Callbacks are removed by calling the off() method on your Firebase database reference. You can remove a single listener by passing it as a parameter to off() .
You just use removeListener(this).
Calling removeEventListener() removes the listener from that location. It will stop firing events after it has completed them for data it's already received. If you're still getting calls to the listener, something else is going on that is unfortunately impossible to say from the code you shared.
This still applies until now, as you cannot remove all listeners at once.
To check for any updates you can see this link: https://firebase.google.com/support/release-notes/android
Currently, you can do it inside onDestroy()
protected void onDestroy(){
super.onDestroy();
yourdatabasereference.removeEventListener(Listenernamehere);
}
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