Usually in my fragments I attach a listener in onAttach() and nullify the listener in onDetach().
Is setting the listener to null in onDetach() necessary?
Although I do it because it makes the code look more symmetric, it doesn't seem necessary since the fragment is already destroyed because onDestroyView() and onDestroy() were already called before according to the fragment's lifecycle.
Thanks in advance.
It makes sense if you want to notify the listener of an finished AsyncTask but you are not interested in the result if the Fragment is not attached anymore. In the onPostExecute you then check if the listener is still present and if so use it.
So yes, there is at least one use cases where it makes sense to set the listener to null.
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