Stay organized with collections
Save and categorize content based on your preferences.
OnBackInvokedCallback
public
interface
OnBackInvokedCallback
android.window.OnBackInvokedCallback
|
Known indirect subclasses
OnBackAnimationCallback |
Interface for applications to register back animation callbacks along their custom back
handling.
|
|
Callback allowing applications to handle back events in place of the system.
Callback instances can be added to and removed from OnBackInvokedDispatcher
, which
is held at window level and accessible through Activity.getOnBackInvokedDispatcher()
,
Dialog.getOnBackInvokedDispatcher()
, Window.getOnBackInvokedDispatcher()
and View.findOnBackInvokedDispatcher()
.
When back is triggered, callbacks on the in-focus window are invoked in reverse order in which
they are added within the same priority. Between different priorities, callbacks with higher
priority are invoked first.
This replaces Activity.onBackPressed()
, Dialog.onBackPressed()
and
KeyEvent.KEYCODE_BACK
If you want to customize back animation behaviors, in addition to handling back invocations,
register its subclass instances OnBackAnimationCallback
instead.
Summary
Public methods |
abstract
void
|
onBackInvoked()
Called when a back gesture has been completed and committed, or back button pressed
has been released and committed.
|
Public methods
onBackInvoked
public abstract void onBackInvoked ()
Called when a back gesture has been completed and committed, or back button pressed
has been released and committed.
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-02-10 UTC.
[null,null,["Last updated 2025-02-10 UTC."],[],[],null,["# OnBackInvokedCallback\n\nAdded in [API level 33](/guide/topics/manifest/uses-sdk-element#ApiLevels) \nSummary: [Methods](#pubmethods) \n\nOnBackInvokedCallback\n=====================\n\n*** ** * ** ***\n\n[Kotlin](/reference/kotlin/android/window/OnBackInvokedCallback \"View this page in Kotlin\") \\|Java\n\n\n`\npublic\n\n\ninterface\nOnBackInvokedCallback\n`\n\n\n`\n\n\n`\n\n|--------------------------------------|\n| android.window.OnBackInvokedCallback |\n\n|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| Known indirect subclasses [OnBackAnimationCallback](/reference/android/window/OnBackAnimationCallback) |------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------| | [OnBackAnimationCallback](/reference/android/window/OnBackAnimationCallback) | Interface for applications to register back animation callbacks along their custom back handling. | |\n\n\u003cbr /\u003e\n\n*** ** * ** ***\n\nCallback allowing applications to handle back events in place of the system.\n\n\nCallback instances can be added to and removed from [OnBackInvokedDispatcher](/reference/android/window/OnBackInvokedDispatcher), which\nis held at window level and accessible through [Activity.getOnBackInvokedDispatcher()](/reference/android/app/Activity#getOnBackInvokedDispatcher()),\n[Dialog.getOnBackInvokedDispatcher()](/reference/android/app/Dialog#getOnBackInvokedDispatcher()), [Window.getOnBackInvokedDispatcher()](/reference/android/view/Window#getOnBackInvokedDispatcher())\nand [View.findOnBackInvokedDispatcher()](/reference/android/view/View#findOnBackInvokedDispatcher()).\n\n\nWhen back is triggered, callbacks on the in-focus window are invoked in reverse order in which\nthey are added within the same priority. Between different priorities, callbacks with higher\npriority are invoked first.\n\n\nThis replaces [Activity.onBackPressed()](/reference/android/app/Activity#onBackPressed()), [Dialog.onBackPressed()](/reference/android/app/Dialog#onBackPressed()) and\n[KeyEvent.KEYCODE_BACK](/reference/android/view/KeyEvent#KEYCODE_BACK)\n\n\nIf you want to customize back animation behaviors, in addition to handling back invocations,\nregister its subclass instances [OnBackAnimationCallback](/reference/android/window/OnBackAnimationCallback) instead.\n\n\u003cbr /\u003e\n\n**See also:**\n\n- [registerOnBackInvokedCallback(priority, OnBackInvokedCallback)\n to specify callback priority.](/reference/android/window/OnBackInvokedDispatcher#registerOnBackInvokedCallback(int,%20android.window.OnBackInvokedCallback))\n\nSummary\n-------\n\n| ### Public methods ||\n|------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| ` abstract void` | ` `[onBackInvoked](/reference/android/window/OnBackInvokedCallback#onBackInvoked())`() ` Called when a back gesture has been completed and committed, or back button pressed has been released and committed. |\n\nPublic methods\n--------------\n\n### onBackInvoked\n\nAdded in [API level 33](/guide/topics/manifest/uses-sdk-element#ApiLevels) \n\n```\npublic abstract void onBackInvoked ()\n```\n\nCalled when a back gesture has been completed and committed, or back button pressed\nhas been released and committed.\n\n\u003cbr /\u003e"]]