1 /*
2  * Copyright (C) 2022 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package android.window;
18 
19 import android.app.Activity;
20 import android.app.Dialog;
21 import android.view.View;
22 import android.view.Window;
23 
24 /**
25  * Callback allowing applications to handle back events in place of the system.
26  * <p>
27  * Callback instances can be added to and removed from {@link OnBackInvokedDispatcher}, which
28  * is held at window level and accessible through {@link Activity#getOnBackInvokedDispatcher()},
29  * {@link Dialog#getOnBackInvokedDispatcher()}, {@link Window#getOnBackInvokedDispatcher()}
30  * and {@link View#findOnBackInvokedDispatcher()}.
31  * <p>
32  * When back is triggered, callbacks on the in-focus window are invoked in reverse order in which
33  * they are added within the same priority. Between different priorities, callbacks with higher
34  * priority are invoked first.
35  * <p>
36  * This replaces {@link Activity#onBackPressed()}, {@link Dialog#onBackPressed()} and
37  * {@link android.view.KeyEvent#KEYCODE_BACK}
38  * <p>
39  * If you want to customize back animation behaviors, in addition to handling back invocations,
40  * register its subclass instances {@link OnBackAnimationCallback} instead.
41  * <p>
42  * @see OnBackInvokedDispatcher#registerOnBackInvokedCallback(int, OnBackInvokedCallback)
43  * registerOnBackInvokedCallback(priority, OnBackInvokedCallback)
44  * to specify callback priority.
45  */
46 @SuppressWarnings("deprecation")
47 public interface OnBackInvokedCallback {
48     /**
49      * Called when a back gesture has been completed and committed, or back button pressed
50      * has been released and committed.
51      */
onBackInvoked()52     void onBackInvoked();
53 }
54