FragmentManager.FragmentLifecycleCallbacks


public abstract class FragmentManager.FragmentLifecycleCallbacks


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

Summary

Public constructors

Public methods

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 CREATED callback.

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

Called after the fragment has been attached to its host.

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

Called after the fragment has returned from the FragmentManager's call to onCreate.

void

Called after the fragment has returned from the FragmentManager's call to onDestroy.

void

Called after the fragment has returned from the FragmentManager's call to onDetach.

void

Called after the fragment has returned from the FragmentManager's call to onPause.

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

Called right before the fragment's onAttach method is called.

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

Called right before the fragment's onCreate method is called.

void

Called after the fragment has returned from the FragmentManager's call to onResume.

void

Called after the fragment has returned from the FragmentManager's call to onSaveInstanceState.

void

Called after the fragment has returned from the FragmentManager's call to onStart.

void

Called after the fragment has returned from the FragmentManager's call to onStop.

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 onCreateView.

void

Called after the fragment has returned from the FragmentManager's call to onDestroyView.

Public constructors

FragmentLifecycleCallbacks

Added in 1.1.0
public FragmentLifecycleCallbacks()

Public methods

onFragmentActivityCreated

Added in 1.1.0
Deprecated in 1.3.0
public void onFragmentActivityCreated(
    @NonNull FragmentManager fm,
    @NonNull Fragment f,
    @Nullable Bundle savedInstanceState
)

Called after the fragment has returned from the FragmentManager's call to onActivityCreated. 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

Added in 1.1.0
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

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

Called after the fragment has returned from the FragmentManager's call to onCreate. 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

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

Called after the fragment has returned from the FragmentManager's call to onDestroy.

Parameters
@NonNull FragmentManager fm

Host FragmentManager

@NonNull Fragment f

Fragment changing state

onFragmentDetached

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

Called after the fragment has returned from the FragmentManager's call to onDetach.

Parameters
@NonNull FragmentManager fm

Host FragmentManager

@NonNull Fragment f

Fragment changing state

onFragmentPaused

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

Called after the fragment has returned from the FragmentManager's call to onPause.

Parameters
@NonNull FragmentManager fm

Host FragmentManager

@NonNull Fragment f

Fragment changing state

onFragmentPreAttached

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

Called right before the fragment's onAttach 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

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

Called right before the fragment's onCreate 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

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

Called after the fragment has returned from the FragmentManager's call to onResume.

Parameters
@NonNull FragmentManager fm

Host FragmentManager

@NonNull Fragment f

Fragment changing state

onFragmentSaveInstanceState

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

Called after the fragment has returned from the FragmentManager's call to onSaveInstanceState.

Parameters
@NonNull FragmentManager fm

Host FragmentManager

@NonNull Fragment f

Fragment changing state

@NonNull Bundle outState

Saved state bundle for the fragment

onFragmentStarted

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

Called after the fragment has returned from the FragmentManager's call to onStart.

Parameters
@NonNull FragmentManager fm

Host FragmentManager

@NonNull Fragment f

Fragment changing state

onFragmentStopped

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

Called after the fragment has returned from the FragmentManager's call to onStop.

Parameters
@NonNull FragmentManager fm

Host FragmentManager

@NonNull Fragment f

Fragment changing state

onFragmentViewCreated

Added in 1.1.0
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 onCreateView.

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

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

Called after the fragment has returned from the FragmentManager's call to onDestroyView.

Parameters
@NonNull FragmentManager fm

Host FragmentManager

@NonNull Fragment f

Fragment changing state