{% setvar book_path %}/reference/androidx/_book.yaml{% endsetvar %} {% include "_shared/_reference-head-tags.html" %}

FragmentManager.FragmentLifecycleCallbacks

{% setvar page_path %}androidx/fragment/app/FragmentManager.FragmentLifecycleCallbacks.html{% endsetvar %} {% setvar can_switch %}1{% endsetvar %} {% include "reference/_java_switcher2.md" %}

public abstract class FragmentManager.FragmentLifecycleCallbacks


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

Summary

Public constructors

Public methods

@NonNull void
onFragmentActivityCreated(
    @NonNull FragmentManager fm,
    @NonNull Fragment f,
    @Nullable Bundle savedInstanceState
)

This method is deprecated.

To get a callback specifically when a Fragment activity's onCreate is called, register a androidx.lifecycle.LifecycleObserver on the Activity's Lifecycle in onFragmentAttached, removing it when it receives the Lifecycle.State#CREATED callback.

@NonNull void
onFragmentAttached(
    @NonNull FragmentManager fm,
    @NonNull Fragment f,
    @NonNull Context context
)

Called after the fragment has been attached to its host.

@NonNull void
onFragmentCreated(
    @NonNull FragmentManager fm,
    @NonNull Fragment f,
    @Nullable Bundle savedInstanceState
)

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

@NonNull void

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

@NonNull void

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

@NonNull void

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

@NonNull void
onFragmentPreAttached(
    @NonNull FragmentManager fm,
    @NonNull Fragment f,
    @NonNull Context context
)

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

@NonNull void
onFragmentPreCreated(
    @NonNull FragmentManager fm,
    @NonNull Fragment f,
    @Nullable Bundle savedInstanceState
)

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

@NonNull void

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

@NonNull void
onFragmentSaveInstanceState(
    @NonNull FragmentManager fm,
    @NonNull Fragment f,
    @NonNull Bundle outState
)

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

@NonNull void

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

@NonNull void

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

@NonNull void
onFragmentViewCreated(
    @NonNull FragmentManager fm,
    @NonNull Fragment f,
    @NonNull View v,
    @Nullable Bundle savedInstanceState
)

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

@NonNull void

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

Public constructors

FragmentLifecycleCallbacks

@NonNull
public FragmentLifecycleCallbacks()

Public methods

onFragmentActivityCreated

@NonNull
public void onFragmentActivityCreated(
    @NonNull FragmentManager fm,
    @NonNull Fragment f,
    @Nullable Bundle savedInstanceState
)

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
@NonNull FragmentManager fm

Host FragmentManager

@NonNull Fragment f

Fragment changing state

@Nullable Bundle savedInstanceState

Saved instance bundle from a previous instance

onFragmentAttached

@NonNull
public void onFragmentAttached(
    @NonNull FragmentManager fm,
    @NonNull Fragment f,
    @NonNull Context context
)

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

Parameters
@NonNull FragmentManager fm

Host FragmentManager

@NonNull Fragment f

Fragment changing state

@NonNull Context context

Context that the Fragment was attached to

onFragmentCreated

@NonNull
public void onFragmentCreated(
    @NonNull FragmentManager fm,
    @NonNull Fragment f,
    @Nullable Bundle savedInstanceState
)

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
@NonNull FragmentManager fm

Host FragmentManager

@NonNull Fragment f

Fragment changing state

@Nullable Bundle savedInstanceState

Saved instance bundle from a previous instance

onFragmentDestroyed

@NonNull
public void onFragmentDestroyed(@NonNull FragmentManager fm, @NonNull Fragment f)

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

Parameters
@NonNull FragmentManager fm

Host FragmentManager

@NonNull Fragment f

Fragment changing state

onFragmentDetached

@NonNull
public void onFragmentDetached(@NonNull FragmentManager fm, @NonNull Fragment f)

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

Parameters
@NonNull FragmentManager fm

Host FragmentManager

@NonNull Fragment f

Fragment changing state

onFragmentPaused

@NonNull
public void onFragmentPaused(@NonNull FragmentManager fm, @NonNull Fragment f)

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

Parameters
@NonNull FragmentManager fm

Host FragmentManager

@NonNull Fragment f

Fragment changing state

onFragmentPreAttached

@NonNull
public void onFragmentPreAttached(
    @NonNull FragmentManager fm,
    @NonNull Fragment f,
    @NonNull Context context
)

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
@NonNull FragmentManager fm

Host FragmentManager

@NonNull Fragment f

Fragment changing state

@NonNull Context context

Context that the Fragment is being attached to

onFragmentPreCreated

@NonNull
public void onFragmentPreCreated(
    @NonNull FragmentManager fm,
    @NonNull Fragment f,
    @Nullable Bundle savedInstanceState
)

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
@NonNull FragmentManager fm

Host FragmentManager

@NonNull Fragment f

Fragment changing state

@Nullable Bundle savedInstanceState

Saved instance bundle from a previous instance

onFragmentResumed

@NonNull
public void onFragmentResumed(@NonNull FragmentManager fm, @NonNull Fragment f)

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

Parameters
@NonNull FragmentManager fm

Host FragmentManager

@NonNull Fragment f

Fragment changing state

onFragmentSaveInstanceState

@NonNull
public void onFragmentSaveInstanceState(
    @NonNull FragmentManager fm,
    @NonNull Fragment f,
    @NonNull Bundle outState
)

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

Parameters
@NonNull FragmentManager fm

Host FragmentManager

@NonNull Fragment f

Fragment changing state

@NonNull Bundle outState

Saved state bundle for the fragment

onFragmentStarted

@NonNull
public void onFragmentStarted(@NonNull FragmentManager fm, @NonNull Fragment f)

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

Parameters
@NonNull FragmentManager fm

Host FragmentManager

@NonNull Fragment f

Fragment changing state

onFragmentStopped

@NonNull
public void onFragmentStopped(@NonNull FragmentManager fm, @NonNull Fragment f)

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

Parameters
@NonNull FragmentManager fm

Host FragmentManager

@NonNull Fragment f

Fragment changing state

onFragmentViewCreated

@NonNull
public void onFragmentViewCreated(
    @NonNull FragmentManager fm,
    @NonNull Fragment f,
    @NonNull View v,
    @Nullable Bundle savedInstanceState
)

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

Parameters
@NonNull FragmentManager fm

Host FragmentManager

@NonNull Fragment f

Fragment that created and owns the view

@NonNull View v

View returned by the fragment

@Nullable Bundle savedInstanceState

Saved instance bundle from a previous instance

onFragmentViewDestroyed

@NonNull
public void onFragmentViewDestroyed(@NonNull FragmentManager fm, @NonNull Fragment f)

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

Parameters
@NonNull FragmentManager fm

Host FragmentManager

@NonNull Fragment f

Fragment changing state