SystemOnBackInvokedCallbacks
class SystemOnBackInvokedCallbacks
kotlin.Any | |
↳ | android.window.SystemOnBackInvokedCallbacks |
Utility class providing OnBackInvokedCallback
s to override the default behavior when system back is invoked. e.g. Activity.finish
By registering these callbacks with the OnBackInvokedDispatcher
, the system can trigger specific behaviors and play corresponding ahead-of-time animations when the back gesture is invoked.
For example, to trigger the Activity.moveTaskToBack
behavior:
OnBackInvokedDispatcher dispatcher = activity.getOnBackInvokedDispatcher(); dispatcher.registerOnBackInvokedCallback( OnBackInvokedDispatcher.PRIORITY_DEFAULT, SystemOnBackInvokedCallbacks.moveTaskToBackCallback(activity));
Summary
Public methods | |
---|---|
static OnBackInvokedCallback |
finishAndRemoveTaskCallback(activity: Activity) Get a callback to triggers |
static OnBackInvokedCallback |
moveTaskToBackCallback(activity: Activity) Get a callback to triggers |
Public methods
finishAndRemoveTaskCallback
static fun finishAndRemoveTaskCallback(activity: Activity): OnBackInvokedCallback
Get a callback to triggers Activity.finishAndRemoveTask()
on the associated Activity
. If the activity is the root activity of its task, the entire task will be removed from the recents task. The activity will be finished in all cases. The system will play the corresponding transition animation.
Parameters | |
---|---|
activity |
Activity: The associated Activity This value cannot be null . |
Return | |
---|---|
OnBackInvokedCallback |
This value cannot be null . |
moveTaskToBackCallback
static fun moveTaskToBackCallback(activity: Activity): OnBackInvokedCallback
Get a callback to triggers Activity.moveTaskToBack(boolean)
on the associated Activity
, moving the task containing the activity to the background. The system will play the corresponding transition animation, regardless of whether the activity is the root activity of the task.
Parameters | |
---|---|
activity |
Activity: The associated Activity This value cannot be null . |
Return | |
---|---|
OnBackInvokedCallback |
This value cannot be null . |