Exploring Android 13: Predictive Back Gesture

M Farhan Majid
3 min readJul 16, 2022

Android 13 (Tiramisu)’s new APIs and features are ready to be tried out by developers. One of them is a predictive back gesture.

Predictive back gesture is a transition animation for back gesture that will let users preview the destination of the back gesture before they complete it. This way users can decide whether to continue the gesture or stay in the current view.

Unfortunately, as of the writing of this article, Android 13 is still in Beta phase. We can’t actually try out the animation ourselves until Android 13 is in its Final Release phase .

What we have now is only the mockup of the animation:

Mockup of the predictive back gesture look and feel on a phone (Source: developer.android.com)

Even though we can’t see predictive back gesture directly now, we can prepare our app to support the animation. Let’s create a simple app for it!

Where’s the Source Code?

Step by Step Explanation

Follow the steps provided below to make this application.

1. As of the writing of this article, Android 13 can only be used with the preview release of Android Studio. Therefore, you must go to this page, and download the Canary Build of Android Studio.

2. Once installed, you need to install the Android 13 SDK. You can do this by clicking Tools > SDK Manager. In the SDK Platforms tab, select Android 13. In the SDK Tools tab, select Android SDK Build-Tools 33. Click OK to install the SDK.

3. Once SDK is installed, open the Android Studio. Create new project with Empty Activity option.

4. First off, you need to change the target and compile SDK version of this app. Open app/build.gradle and you would see something like this:

Change the compileSdk and targetSdk to use the Android 13 SDK like shown in the code snippet below. Don’t forget to click Sync Now after.

5. Next, we need to opt in to predictive back gesture by setting android:enableOnBackInvokedCallback to true in our AndroidManifest.xml file:

If this property is not set, it will default to false so you can opt in whenever your app is ready for predictive back gesture.

6. Next, we need to update appcompat library to the latest version in our app/build.gradle file like this:

7. In our next step here, there is a difference between apps that use AndroidX and the ones that don’t:

Take a look at the code snippet below for the detail. Notice the differences. Firstly, with AndroidX, you don’t need to unregister the callback because it’s handled internally when you call addCallback() method. Secondly, with AndroidX, you don’t have to check the device’s build version first to make sure that it has at least Android 13.

Conclusion: Use AndroidX if possible for easier life :)

8. That’s it! That’s how you prepare your app to use predictive back gesture for Android 13.

As always, thanks for reading!

Want to learn more about Android 13?

Check out all of our articles from “Exploring Android 13” series here:

Exploring Android 13 (Tiramisu)

10 stories