Stay organized with collections
Save and categorize content based on your preferences.
OnBackInvokedDispatcher
public
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
PRIORITY_DEFAULT
public static final int PRIORITY_DEFAULT
Default priority level of OnBackInvokedCallback
s.
Constant Value:
0
(0x00000000)
PRIORITY_OVERLAY
public static final int PRIORITY_OVERLAY
Priority level of OnBackInvokedCallback
s for overlays such as menus and
navigation drawers that should receive back dispatch before non-overlays.
Constant Value:
1000000
(0x000f4240)
PRIORITY_SYSTEM_NAVIGATION_OBSERVER
public static final int PRIORITY_SYSTEM_NAVIGATION_OBSERVER
Priority level of OnBackInvokedCallback
s designed to observe system-level back
handling.
Callbacks registered with this priority are invoked only when a back event is not
consumed by any other registered OnBackInvokedCallback
with a priority of
PRIORITY_DEFAULT
or higher. This means they are called when the system is about
to perform its default back navigation action, such as finishing the current activity or
executing a back-to-home animation.
These callbacks are purely observational. They do not consume the back event and
cannot intercept it. Their invocation has no impact on the normal back navigation flow,
making them suitable for logging, analytics, or triggering actions that should not
prevent the system's own back handling.
The invocation order for multiple callbacks registered with this priority is undefined.
On API level 36 only, there is a restriction that only one callback with
PRIORITY_SYSTEM_NAVIGATION_OBSERVER
can be registered at a time. On API level 37 and
higher, the number of registered observer callbacks is unrestricted.
Constant Value:
-2
(0xfffffffe)
Public methods
registerOnBackInvokedCallback
public abstract void registerOnBackInvokedCallback (int priority,
OnBackInvokedCallback callback)
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 PRIORITY_DEFAULT , PRIORITY_OVERLAY , or PRIORITY_SYSTEM_NAVIGATION_OBSERVER
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 . |
unregisterOnBackInvokedCallback
public abstract void unregisterOnBackInvokedCallback (OnBackInvokedCallback callback)
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 . |
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-08-20 UTC.
[null,null,["Last updated 2025-08-20 UTC."],[],[],null,["# OnBackInvokedDispatcher\n\nAdded in [API level 33](/guide/topics/manifest/uses-sdk-element#ApiLevels) \n\nOnBackInvokedDispatcher\n=======================\n\n*** ** * ** ***\n\n[Kotlin](/reference/kotlin/android/window/OnBackInvokedDispatcher \"View this page in Kotlin\") \\|Java\n\n\n`\npublic\n\n\ninterface\nOnBackInvokedDispatcher\n`\n\n\n`\n\n\n`\n\n|----------------------------------------|\n| android.window.OnBackInvokedDispatcher |\n\n\u003cbr /\u003e\n\n*** ** * ** ***\n\nDispatcher to register [OnBackInvokedCallback](/reference/android/window/OnBackInvokedCallback) instances for handling\nback invocations.\n\nIt also provides interfaces to update the attributes of [OnBackInvokedCallback](/reference/android/window/OnBackInvokedCallback).\nAttribute updates are proactively pushed to the window manager if they change the dispatch\ntarget (a.k.a. the callback to be invoked next), or its behavior.\n\nSummary\n-------\n\n| ### Constants ||\n|-------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `int` | [PRIORITY_DEFAULT](/reference/android/window/OnBackInvokedDispatcher#PRIORITY_DEFAULT) Default priority level of [OnBackInvokedCallback](/reference/android/window/OnBackInvokedCallback)s. |\n| `int` | [PRIORITY_OVERLAY](/reference/android/window/OnBackInvokedDispatcher#PRIORITY_OVERLAY) Priority level of [OnBackInvokedCallback](/reference/android/window/OnBackInvokedCallback)s for overlays such as menus and navigation drawers that should receive back dispatch before non-overlays. |\n| `int` | [PRIORITY_SYSTEM_NAVIGATION_OBSERVER](/reference/android/window/OnBackInvokedDispatcher#PRIORITY_SYSTEM_NAVIGATION_OBSERVER) Priority level of [OnBackInvokedCallback](/reference/android/window/OnBackInvokedCallback)s designed to observe system-level back handling. |\n\n| ### Public methods ||\n|------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| ` abstract void` | ` `[registerOnBackInvokedCallback](/reference/android/window/OnBackInvokedDispatcher#registerOnBackInvokedCallback(int,%20android.window.OnBackInvokedCallback))`(int priority, `[OnBackInvokedCallback](/reference/android/window/OnBackInvokedCallback)` callback) ` Registers a [OnBackInvokedCallback](/reference/android/window/OnBackInvokedCallback). |\n| ` abstract void` | ` `[unregisterOnBackInvokedCallback](/reference/android/window/OnBackInvokedDispatcher#unregisterOnBackInvokedCallback(android.window.OnBackInvokedCallback))`(`[OnBackInvokedCallback](/reference/android/window/OnBackInvokedCallback)` callback) ` Unregisters a [OnBackInvokedCallback](/reference/android/window/OnBackInvokedCallback). |\n\nConstants\n---------\n\n### PRIORITY_DEFAULT\n\nAdded in [API level 33](/guide/topics/manifest/uses-sdk-element#ApiLevels) \n\n```\npublic static final int PRIORITY_DEFAULT\n```\n\nDefault priority level of [OnBackInvokedCallback](/reference/android/window/OnBackInvokedCallback)s.\n\n\u003cbr /\u003e\n\nConstant Value:\n\n0\n(0x00000000)\n\n\n### PRIORITY_OVERLAY\n\nAdded in [API level 33](/guide/topics/manifest/uses-sdk-element#ApiLevels) \n\n```\npublic static final int PRIORITY_OVERLAY\n```\n\nPriority level of [OnBackInvokedCallback](/reference/android/window/OnBackInvokedCallback)s for overlays such as menus and\nnavigation drawers that should receive back dispatch before non-overlays.\n\n\u003cbr /\u003e\n\nConstant Value:\n\n1000000\n(0x000f4240)\n\n\n### PRIORITY_SYSTEM_NAVIGATION_OBSERVER\n\nAdded in [API level 36](/guide/topics/manifest/uses-sdk-element#ApiLevels) \n\n```\npublic static final int PRIORITY_SYSTEM_NAVIGATION_OBSERVER\n```\n\nPriority level of [OnBackInvokedCallback](/reference/android/window/OnBackInvokedCallback)s designed to observe system-level back\nhandling.\n\nCallbacks registered with this priority are invoked only when a back event is not\nconsumed by any other registered [OnBackInvokedCallback](/reference/android/window/OnBackInvokedCallback) with a priority of\n[PRIORITY_DEFAULT](/reference/android/window/OnBackInvokedDispatcher#PRIORITY_DEFAULT) or higher. This means they are called when the system is about\nto perform its default back navigation action, such as finishing the current activity or\nexecuting a back-to-home animation.\n\nThese callbacks are purely observational. They do not consume the back event and\ncannot intercept it. Their invocation has no impact on the normal back navigation flow,\nmaking them suitable for logging, analytics, or triggering actions that should not\nprevent the system's own back handling.\n\nThe invocation order for multiple callbacks registered with this priority is undefined.\n\nOn API level 36 only, there is a restriction that only one callback with\n[PRIORITY_SYSTEM_NAVIGATION_OBSERVER](/reference/android/window/OnBackInvokedDispatcher#PRIORITY_SYSTEM_NAVIGATION_OBSERVER) can be registered at a time. On API level 37 and\nhigher, the number of registered observer callbacks is unrestricted.\n\n\u003cbr /\u003e\n\nConstant Value:\n\n-2\n(0xfffffffe)\n\n\nPublic methods\n--------------\n\n### registerOnBackInvokedCallback\n\nAdded in [API level 33](/guide/topics/manifest/uses-sdk-element#ApiLevels) \n\n```\npublic abstract void registerOnBackInvokedCallback (int priority, \n OnBackInvokedCallback callback)\n```\n\nRegisters a [OnBackInvokedCallback](/reference/android/window/OnBackInvokedCallback).\n\nWithin the same priority level, callbacks are invoked in the reverse order in which\nthey are registered. Higher priority callbacks are invoked before lower priority ones.\n\n\u003cbr /\u003e\n\n| Parameters ||\n|------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `priority` | `int`: The priority of the callback. Value is [PRIORITY_DEFAULT](/reference/android/window/OnBackInvokedDispatcher#PRIORITY_DEFAULT), [PRIORITY_OVERLAY](/reference/android/window/OnBackInvokedDispatcher#PRIORITY_OVERLAY), or [PRIORITY_SYSTEM_NAVIGATION_OBSERVER](/reference/android/window/OnBackInvokedDispatcher#PRIORITY_SYSTEM_NAVIGATION_OBSERVER) Value is 0 or greater \u003cbr /\u003e |\n| `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`. \u003cbr /\u003e |\n\n| Throws ||\n|---------------------------------------------------------------------------|------------------------------|\n| [IllegalArgumentException](/reference/java/lang/IllegalArgumentException) | if the priority is negative. |\n\n### unregisterOnBackInvokedCallback\n\nAdded in [API level 33](/guide/topics/manifest/uses-sdk-element#ApiLevels) \n\n```\npublic abstract void unregisterOnBackInvokedCallback (OnBackInvokedCallback callback)\n```\n\nUnregisters a [OnBackInvokedCallback](/reference/android/window/OnBackInvokedCallback).\n\n\u003cbr /\u003e\n\n| Parameters ||\n|------------|-----------------------------------------------------------------------------------------------------------------------------------------------------|\n| `callback` | `OnBackInvokedCallback`: The callback to be unregistered. Does nothing if the callback has not been registered. This value cannot be `null`. \u003cbr /\u003e |"]]