FragmentManager.OnBackStackChangedListener


public interface FragmentManager.OnBackStackChangedListener


Interface to watch for changes to the back stack.

Summary

Public methods

default void

Called whenever a predictive back gesture is cancelled.

default void

Called whenever the contents of a back stack change is committed.

default void

Called whenever a predictive back gesture is changing the back stack.

default void

Called whenever the contents of the back stack are starting to be changed, before any fragment actually changes its lifecycle state.

abstract void

Called whenever the contents of the back stack change, after the fragment manager has moved all of the fragments to their final state.

Public methods

onBackStackChangeCancelled

Added in 1.7.0
@MainThread
default void onBackStackChangeCancelled()

Called whenever a predictive back gesture is cancelled.

This is called immediately after onBackStackChangeProgressed once a predictive back gesture has been cancelled and will place the FragmentManager back into the state before the predictive back gesture was started.

onBackStackChangeCommitted

Added in 1.6.0
@MainThread
default void onBackStackChangeCommitted(@NonNull Fragment fragment, boolean pop)

Called whenever the contents of a back stack change is committed. If this is caused by a forward transaction and the given fragment is incoming, it will return false from isRemoving. If this is caused by a pop operation and the given fragment is being popped, it will return true from isRemoving.

This is called immediately after onBackStackChangeStarted for a forward transaction or for a non-predictive back pop. If this is caused by a predictive back gesture, it will be called after onBackStackChangeProgressed before the fragment moves to the final state.

Parameters
@NonNull Fragment fragment

one of the fragments that is affected by the committed back stack change

boolean pop

true, if this callback was triggered by a pop operation, false otherwise

onBackStackChangeProgressed

Added in 1.7.0
@MainThread
default void onBackStackChangeProgressed(@NonNull BackEventCompat backEventCompat)

Called whenever a predictive back gesture is changing the back stack. This will continue to be called with an updated BackEventCompat object until the gesture is either cancelled or completed.

This is called immediately after onBackStackChangeStarted during a predictive back gesture. If the gesture is completed, this will be followed by onBackStackChangeCommitted and if it is cancelled, it will be followed by onBackStackChangeCancelled.

Parameters
@NonNull BackEventCompat backEventCompat

provides the current progress of the active predictive back gesture

onBackStackChangeStarted

Added in 1.6.0
@MainThread
default void onBackStackChangeStarted(@NonNull Fragment fragment, boolean pop)

Called whenever the contents of the back stack are starting to be changed, before any fragment actually changes its lifecycle state. If this is caused by a forward transaction and the given fragment is incoming, it will return false from isRemoving. If this is caused by a pop operation and the given fragment is being popped, it will return true from isRemoving.

This is the first callback that will be delivered to the listener. If the transaction is caused by a predictive back gesture, it will be followed by an onBackStackChangeProgressed callback otherwise, the next callback will be onBackStackChangeCommitted.

Parameters
@NonNull Fragment fragment

one of the fragments that is affected by the starting back stack change

boolean pop

true, if this callback was triggered by a pop operation, false otherwise

onBackStackChanged

Added in 1.1.0
@MainThread
abstract void onBackStackChanged()

Called whenever the contents of the back stack change, after the fragment manager has moved all of the fragments to their final state.

This is the final callback that will be delivered to the listener in all cases except for when the predictive back gesture is cancelled. It will be called after onBackStackChangeCommitted.