SystemOnBackInvokedCallbacks


public final class SystemOnBackInvokedCallbacks
extends Object

java.lang.Object
   ↳ android.window.SystemOnBackInvokedCallbacks


Utility class providing OnBackInvokedCallbacks 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 Activity.finishAndRemoveTask() on the associated Activity.

static OnBackInvokedCallback moveTaskToBackCallback(Activity activity)

Get a callback to triggers Activity.moveTaskToBack(boolean) on the associated Activity, moving the task containing the activity to the background.

Inherited methods

Object clone()

Creates and returns a copy of this object.

boolean equals(Object obj)

Indicates whether some other object is "equal to" this one.

void finalize()

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.

final Class<?> getClass()

Returns the runtime class of this Object.

int hashCode()

Returns a hash code value for the object.

final void notify()

Wakes up a single thread that is waiting on this object's monitor.

final void notifyAll()

Wakes up all threads that are waiting on this object's monitor.

String toString()

Returns a string representation of the object.

final void wait(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 wait(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 wait()

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

Public methods

finishAndRemoveTaskCallback

public static OnBackInvokedCallback finishAndRemoveTaskCallback (Activity activity)

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.

Returns
OnBackInvokedCallback This value cannot be null.

moveTaskToBackCallback

public static OnBackInvokedCallback moveTaskToBackCallback (Activity activity)

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.

Returns
OnBackInvokedCallback This value cannot be null.