Added in API level 33

OnBackInvokedDispatcher

interface OnBackInvokedDispatcher
android.window.OnBackInvokedDispatcher

Dispatcher to register OnBackInvokedCallback instances for handling back invocations. It also provides interfaces to update the attributes of OnBackInvokedCallback. Attribute updates are proactively pushed to the window manager if they change the dispatch target (a.k.a. the callback to be invoked next), or its behavior.

Summary

Constants
static Int

Default priority level of OnBackInvokedCallbacks.

static Int

Priority level of OnBackInvokedCallbacks for overlays such as menus and navigation drawers that should receive back dispatch before non-overlays.

Public methods
abstract Unit

Registers a OnBackInvokedCallback.

abstract Unit

Unregisters a OnBackInvokedCallback.

Constants

PRIORITY_DEFAULT

Added in API level 33
static val PRIORITY_DEFAULT: Int

Default priority level of OnBackInvokedCallbacks.

Value: 0

PRIORITY_OVERLAY

Added in API level 33
static val PRIORITY_OVERLAY: Int

Priority level of OnBackInvokedCallbacks for overlays such as menus and navigation drawers that should receive back dispatch before non-overlays.

Value: 1000000

Public methods

registerOnBackInvokedCallback

Added in API level 33
abstract fun registerOnBackInvokedCallback(
    priority: Int,
    callback: OnBackInvokedCallback
): Unit

Registers a OnBackInvokedCallback. Within the same priority level, callbacks are invoked in the reverse order in which they are registered. Higher priority callbacks are invoked before lower priority ones.

Parameters
priority Int: The priority of the callback. Value is android.window.OnBackInvokedDispatcher#PRIORITY_DEFAULT, or android.window.OnBackInvokedDispatcher#PRIORITY_OVERLAY Value is 0 or greater
callback OnBackInvokedCallback: The callback to be registered. If the callback instance has been already registered, the existing instance (no matter its priority) will be unregistered and registered again. This value cannot be null.
Exceptions
IllegalArgumentException if the priority is negative.

unregisterOnBackInvokedCallback

Added in API level 33
abstract fun unregisterOnBackInvokedCallback(callback: OnBackInvokedCallback): Unit

Unregisters a OnBackInvokedCallback.

Parameters
callback OnBackInvokedCallback: The callback to be unregistered. Does nothing if the callback has not been registered. This value cannot be null.