Listener for the fragment life cycle

If I have a fragment object, is there a way to get notified about the life cycle methods of this fragment?

One of the possible ways to do this is to implement this mechanism in my fragment, and the fragment notifies listeners, but this requires template code, which I need to add in all methods of the fragment. Is there any support for this at the Android platform level?

+5
source share
1 answer

You can register FragmentLifecycleCallbacks with supportFragmentManager.registerFragmentLifecycleCallbacks(callback) . The callback provides all the events of the fragment's life cycle and is active until the fragment is destroyed (in this case, the callback will be automatically unregistered for you).

+4
source

All Articles