Join us for ⁠#Android11: The Beta Launch Show on June 3!

FragmentLifecycleCallbacks

abstract class FragmentLifecycleCallbacks
kotlin.Any
   ↳ androidx.fragment.app.FragmentManager.FragmentLifecycleCallbacks

Callback interface for listening to fragment state changes that happen within a given FragmentManager.

Summary

Public constructors

Callback interface for listening to fragment state changes that happen within a given FragmentManager.

Public methods

open Unit
onFragmentActivityCreated(@NonNull fm: FragmentManager, @NonNull f: Fragment, @Nullable savedInstanceState: Bundle?)

Called after the fragment has returned from the FragmentManager's call to Fragment#onActivityCreated(Bundle).

open Unit
onFragmentAttached(@NonNull fm: FragmentManager, @NonNull f: Fragment, @NonNull context: Context)

Called after the fragment has been attached to its host.

open Unit
onFragmentCreated(@NonNull fm: FragmentManager, @NonNull f: Fragment, @Nullable savedInstanceState: Bundle?)

Called after the fragment has returned from the FragmentManager's call to Fragment#onCreate(Bundle).

open Unit
onFragmentDestroyed(@NonNull fm: FragmentManager, @NonNull f: Fragment)

Called after the fragment has returned from the FragmentManager's call to Fragment#onDestroy().

open Unit
onFragmentDetached(@NonNull fm: FragmentManager, @NonNull f: Fragment)

Called after the fragment has returned from the FragmentManager's call to Fragment#onDetach().

open Unit
onFragmentPaused(@NonNull fm: FragmentManager, @NonNull f: Fragment)

Called after the fragment has returned from the FragmentManager's call to Fragment#onPause().

open Unit
onFragmentPreAttached(@NonNull fm: FragmentManager, @NonNull f: Fragment, @NonNull context: Context)

Called right before the fragment's Fragment#onAttach(Context) method is called.

open Unit
onFragmentPreCreated(@NonNull fm: FragmentManager, @NonNull f: Fragment, @Nullable savedInstanceState: Bundle?)

Called right before the fragment's Fragment#onCreate(Bundle) method is called.

open Unit
onFragmentResumed(@NonNull fm: FragmentManager, @NonNull f: Fragment)

Called after the fragment has returned from the FragmentManager's call to Fragment#onResume().

open Unit
onFragmentSaveInstanceState(@NonNull fm: FragmentManager, @NonNull f: Fragment, @NonNull outState: Bundle)

Called after the fragment has returned from the FragmentManager's call to Fragment#onSaveInstanceState(Bundle).

open Unit
onFragmentStarted(@NonNull fm: FragmentManager, @NonNull f: Fragment)

Called after the fragment has returned from the FragmentManager's call to Fragment#onStart().

open Unit
onFragmentStopped(@NonNull fm: FragmentManager, @NonNull f: Fragment)

Called after the fragment has returned from the FragmentManager's call to Fragment#onStop().

open Unit
onFragmentViewCreated(@NonNull fm: FragmentManager, @NonNull f: Fragment, @NonNull v: View, @Nullable savedInstanceState: Bundle?)

Called after the fragment has returned a non-null view from the FragmentManager's request to Fragment#onCreateView(LayoutInflater, ViewGroup, Bundle).

open Unit
onFragmentViewDestroyed(@NonNull fm: FragmentManager, @NonNull f: Fragment)

Called after the fragment has returned from the FragmentManager's call to Fragment#onDestroyView().

Public constructors

<init>

FragmentLifecycleCallbacks()

Callback interface for listening to fragment state changes that happen within a given FragmentManager.

Public methods

onFragmentActivityCreated

open fun onFragmentActivityCreated(
    @NonNull fm: FragmentManager,
    @NonNull f: Fragment,
    @Nullable savedInstanceState: Bundle?
): Unit

Deprecated: To get a callback specifically when a Fragment activity's android.app.Activity#onCreate(Bundle) is called, register a androidx.lifecycle.LifecycleObserver on the Activity's Lifecycle in onFragmentAttached(FragmentManager, Fragment, Context), removing it when it receives the Lifecycle.State#CREATED callback.

Called after the fragment has returned from the FragmentManager's call to Fragment#onActivityCreated(Bundle). This will only happen once for any given fragment instance, though the fragment may be attached and detached multiple times.

Parameters
fm FragmentManager: Host FragmentManager
f Fragment: Fragment changing state
savedInstanceState Bundle?: Saved instance bundle from a previous instance

onFragmentAttached

open fun onFragmentAttached(
    @NonNull fm: FragmentManager,
    @NonNull f: Fragment,
    @NonNull context: Context
): Unit

Called after the fragment has been attached to its host. Its host will have had onAttachFragment called before this call happens.

Parameters
fm FragmentManager: Host FragmentManager
f Fragment: Fragment changing state
context Context: Context that the Fragment was attached to

onFragmentCreated

open fun onFragmentCreated(
    @NonNull fm: FragmentManager,
    @NonNull f: Fragment,
    @Nullable savedInstanceState: Bundle?
): Unit

Called after the fragment has returned from the FragmentManager's call to Fragment#onCreate(Bundle). This will only happen once for any given fragment instance, though the fragment may be attached and detached multiple times.

Parameters
fm FragmentManager: Host FragmentManager
f Fragment: Fragment changing state
savedInstanceState Bundle?: Saved instance bundle from a previous instance

onFragmentDestroyed

open fun onFragmentDestroyed(
    @NonNull fm: FragmentManager,
    @NonNull f: Fragment
): Unit

Called after the fragment has returned from the FragmentManager's call to Fragment#onDestroy().

Parameters
fm FragmentManager: Host FragmentManager
f Fragment: Fragment changing state

onFragmentDetached

open fun onFragmentDetached(
    @NonNull fm: FragmentManager,
    @NonNull f: Fragment
): Unit

Called after the fragment has returned from the FragmentManager's call to Fragment#onDetach().

Parameters
fm FragmentManager: Host FragmentManager
f Fragment: Fragment changing state

onFragmentPaused

open fun onFragmentPaused(
    @NonNull fm: FragmentManager,
    @NonNull f: Fragment
): Unit

Called after the fragment has returned from the FragmentManager's call to Fragment#onPause().

Parameters
fm FragmentManager: Host FragmentManager
f Fragment: Fragment changing state

onFragmentPreAttached

open fun onFragmentPreAttached(
    @NonNull fm: FragmentManager,
    @NonNull f: Fragment,
    @NonNull context: Context
): Unit

Called right before the fragment's Fragment#onAttach(Context) method is called. This is a good time to inject any required dependencies or perform other configuration for the fragment before any of the fragment's lifecycle methods are invoked.

Parameters
fm FragmentManager: Host FragmentManager
f Fragment: Fragment changing state
context Context: Context that the Fragment is being attached to

onFragmentPreCreated

open fun onFragmentPreCreated(
    @NonNull fm: FragmentManager,
    @NonNull f: Fragment,
    @Nullable savedInstanceState: Bundle?
): Unit

Called right before the fragment's Fragment#onCreate(Bundle) method is called. This is a good time to inject any required dependencies or perform other configuration for the fragment.

Parameters
fm FragmentManager: Host FragmentManager
f Fragment: Fragment changing state
savedInstanceState Bundle?: Saved instance bundle from a previous instance

onFragmentResumed

open fun onFragmentResumed(
    @NonNull fm: FragmentManager,
    @NonNull f: Fragment
): Unit

Called after the fragment has returned from the FragmentManager's call to Fragment#onResume().

Parameters
fm FragmentManager: Host FragmentManager
f Fragment: Fragment changing state

onFragmentSaveInstanceState

open fun onFragmentSaveInstanceState(
    @NonNull fm: FragmentManager,
    @NonNull f: Fragment,
    @NonNull outState: Bundle
): Unit

Called after the fragment has returned from the FragmentManager's call to Fragment#onSaveInstanceState(Bundle).

Parameters
fm FragmentManager: Host FragmentManager
f Fragment: Fragment changing state
outState Bundle: Saved state bundle for the fragment

onFragmentStarted

open fun onFragmentStarted(
    @NonNull fm: FragmentManager,
    @NonNull f: Fragment
): Unit

Called after the fragment has returned from the FragmentManager's call to Fragment#onStart().

Parameters
fm FragmentManager: Host FragmentManager
f Fragment: Fragment changing state

onFragmentStopped

open fun onFragmentStopped(
    @NonNull fm: FragmentManager,
    @NonNull f: Fragment
): Unit

Called after the fragment has returned from the FragmentManager's call to Fragment#onStop().

Parameters
fm FragmentManager: Host FragmentManager
f Fragment: Fragment changing state

onFragmentViewCreated

open fun onFragmentViewCreated(
    @NonNull fm: FragmentManager,
    @NonNull f: Fragment,
    @NonNull v: View,
    @Nullable savedInstanceState: Bundle?
): Unit

Called after the fragment has returned a non-null view from the FragmentManager's request to Fragment#onCreateView(LayoutInflater, ViewGroup, Bundle).

Parameters
fm FragmentManager: Host FragmentManager
f Fragment: Fragment that created and owns the view
v View: View returned by the fragment
savedInstanceState Bundle?: Saved instance bundle from a previous instance

onFragmentViewDestroyed

open fun onFragmentViewDestroyed(
    @NonNull fm: FragmentManager,
    @NonNull f: Fragment
): Unit

Called after the fragment has returned from the FragmentManager's call to Fragment#onDestroyView().

Parameters
fm FragmentManager: Host FragmentManager
f Fragment: Fragment changing state