In Android, when an Activity is destroyed, should I remove all the listeners
ref.addAuthStateListener(listener);
ref.addListenerForSingleValueEvent(listener);
ref.addChildEventListener(listener);
ref.addValueEventListener(listener);
using ref.removeEventListener(listener)
or they will be destroyed automatically?
I know that for FirebaseRecyclerAdapter
we can use cleanup()
to do the job.
Besides listeners and adapters are there any other objects that we need to cleanup?
Firebase listeners are not automatically removed. You will indeed have to remove them by calling removeEventListener()
, just like you add them.
Whether you remove listeners in onDestroy()
really depends on where you add them. I typically remove them in the event that is the opposite of where I add them. So if I add then in onCreate()
, I remove then (or call cleanup()
in onDestroy()
. Similar for onStart()
/onStop()
and onPause()
/onResume()
.
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