Added in [API level 36](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Methods](https://developer.android.com/reference/android/window/SystemOnBackInvokedCallbacks#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/android/window/SystemOnBackInvokedCallbacks#inhmethods)

# SystemOnBackInvokedCallbacks

*** ** * ** ***

` public final class SystemOnBackInvokedCallbacks `   
` extends https://developer.android.com/reference/java/lang/Object ` ` `

|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.window.SystemOnBackInvokedCallbacks |

<br />

*** ** * ** ***

Utility class providing `https://developer.android.com/reference/android/window/OnBackInvokedCallback`s to override the default behavior when system back is invoked. e.g. `https://developer.android.com/reference/android/app/Activity#finish()`

By registering these callbacks with the `https://developer.android.com/reference/android/window/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 `https://developer.android.com/reference/android/app/Activity#moveTaskToBack(boolean)` behavior:

```
  OnBackInvokedDispatcher dispatcher = activity.getOnBackInvokedDispatcher();
  dispatcher.registerOnBackInvokedCallback(
      OnBackInvokedDispatcher.PRIORITY_DEFAULT,
      SystemOnBackInvokedCallbacks.moveTaskToBackCallback(activity));
```

<br />

## Summary

| ### Public methods ||
|---|---|
| ` static https://developer.android.com/reference/android/window/OnBackInvokedCallback` | ` https://developer.android.com/reference/android/window/SystemOnBackInvokedCallbacks#finishAndRemoveTaskCallback(android.app.Activity)(https://developer.android.com/reference/android/app/Activity activity) ` <br /> Get a callback to triggers `https://developer.android.com/reference/android/app/Activity#finishAndRemoveTask()` on the associated `https://developer.android.com/reference/android/app/Activity`. |
| ` static https://developer.android.com/reference/android/window/OnBackInvokedCallback` | ` https://developer.android.com/reference/android/window/SystemOnBackInvokedCallbacks#moveTaskToBackCallback(android.app.Activity)(https://developer.android.com/reference/android/app/Activity activity) ` <br /> Get a callback to triggers `https://developer.android.com/reference/android/app/Activity#moveTaskToBack(boolean)` on the associated `https://developer.android.com/reference/android/app/Activity`, moving the task containing the activity to the background. |

### Inherited methods

From class ` https://developer.android.com/reference/java/lang/Object ` ` https://developer.android.com/reference/java/lang/Object` ` https://developer.android.com/reference/java/lang/Object#clone()() `

Creates and returns a copy of this object.
` boolean` ` https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj) `

Indicates whether some other object is "equal to" this one.
` void` ` https://developer.android.com/reference/java/lang/Object#finalize()() `

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.
` final https://developer.android.com/reference/java/lang/Class<?>` ` https://developer.android.com/reference/java/lang/Object#getClass()() `

Returns the runtime class of this `Object`.
` int` ` https://developer.android.com/reference/java/lang/Object#hashCode()() `

Returns a hash code value for the object.
` final void` ` https://developer.android.com/reference/java/lang/Object#notify()() `

Wakes up a single thread that is waiting on this object's monitor.
` final void` ` https://developer.android.com/reference/java/lang/Object#notifyAll()() `

Wakes up all threads that are waiting on this object's monitor.
` https://developer.android.com/reference/java/lang/String` ` https://developer.android.com/reference/java/lang/Object#toString()() `

Returns a string representation of the object.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait(long,%20int)(long timeoutMillis, int nanos) `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait(long)(long timeoutMillis) `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait()() `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*.

## Public methods

### finishAndRemoveTaskCallback

Added in [API level 36](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static OnBackInvokedCallback finishAndRemoveTaskCallback (Activity activity)
```

<br />

Get a callback to triggers `https://developer.android.com/reference/android/app/Activity#finishAndRemoveTask()` on the associated `https://developer.android.com/reference/android/app/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.

<br />

<br />

| Parameters ||
|---|---|
| `activity` | `Activity`: The associated `https://developer.android.com/reference/android/app/Activity` This value cannot be `null`. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/window/OnBackInvokedCallback` | This value cannot be `null`. <br /> |

**See also:**

- `https://developer.android.com/reference/android/app/Activity#finishAndRemoveTask()`

### moveTaskToBackCallback

Added in [API level 36](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static OnBackInvokedCallback moveTaskToBackCallback (Activity activity)
```

<br />

Get a callback to triggers `https://developer.android.com/reference/android/app/Activity#moveTaskToBack(boolean)` on the associated `https://developer.android.com/reference/android/app/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.

<br />

<br />

| Parameters ||
|---|---|
| `activity` | `Activity`: The associated `https://developer.android.com/reference/android/app/Activity` This value cannot be `null`. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/window/OnBackInvokedCallback` | This value cannot be `null`. <br /> |

**See also:**

- `https://developer.android.com/reference/android/app/Activity#moveTaskToBack(boolean)`