Thursday, February 9, 2023
HomeMobilePut together your app to help predictive again gestures

Put together your app to help predictive again gestures

Posted by Jason Tang, Product Administration, Diego Zuluaga, Developer Relations, and Michael Mauzy, Developer Documentation

Since we launched gesture navigation in Android 10, customers have signaled they wish to perceive the place a again gesture will take them earlier than they full it.

As step one to addressing this want, we have been creating a predictive again gesture. When a person begins their gesture by swiping again, we’ll present an animated preview of the vacation spot UI, and the person can full the gesture to navigate to that UI if they need – as proven within the following instance.

Though the predictive again gesture received’t be seen to customers in Android 13, we’re making an early model of the UI obtainable as a developer choice for testing beginning in Beta 4. We plan to make the UI obtainable to customers in a future Android launch, and we’d like all apps to be prepared. We’re additionally working with companions to make sure it’s constant throughout gadgets.

Learn on for particulars on how you can check out the brand new gesture and help it in your apps. Including help for predictive again gesture is simple for many apps, and you will get began right now.

We additionally encourage you to submit your suggestions.

Check out the predictive again gesture in Beta 4

To check out the early model of the predictive again gesture obtainable by the developer choice, you’ll must first replace your app to help the predictive again gesture, after which allow the developer choice.

Replace your app to help predictive again gesture

To assist make predictive again gesture useful and constant for customers, we’re transferring to an ahead-of-time mannequin for again occasion dealing with by including new APIs and deprecating current APIs.

The brand new platform APIs and updates to AndroidX Exercise 1.6+ are designed to make your transition from unsupported APIs (KeyEvent#KEYCODE_BACK and OnBackPressed) to the predictive again gesture as clean as potential.

The brand new platform APIs embody OnBackInvokedCallback and OnBackInvokedDispatcher, which AndroidX Exercise 1.6+ helps by the present OnBackPressedCallback and OnBackPressedDispatcher APIs.

You can begin testing this function in two to 4 steps, relying in your current implementation.

To start testing this function:

1. Improve to AndroidX Exercise 1.6.0-alpha05. By upgrading your dependency on AndroidX Exercise, APIs which might be already utilizing the OnBackPressedDispatcher APIs corresponding to Fragments and the Navigation Part will seamlessly work once you opt-in for the predictive again gesture. 

// In your construct.gradle file:
dependencies {

  // Add this along with your different dependencies
  implementation “androidx.exercise:exercise:1.6.0-alpha05”

2. Choose-in for the predictive again gesture. Choose-in your app by setting the EnableOnBackInvokedCallback flag to true on the software degree within the AndroidManifest.xml.




    … >


In case your app doesn’t intercept the again occasion, you are carried out at this step.

Be aware: Choose-in is non-obligatory in Android 13, and will probably be ignored after this model.

3. Create a callback to intercept the system Again button/occasion. If potential, we suggest utilizing the AndroidX APIs as proven under. For non-AndroidX use instances, test the platform API talked about above.

This snippet implements handleOnBackPressed and provides the OnBackPressedCallback to the OnBackPressedDispatcher on the exercise degree.

 val onBackPressedCallback = objectOnBackPressedCallback(true) {

   override enjoyable handleOnBackPressed() {

     // Your corporation logic to deal with the again pressed occasion





4. When your app is able to cease intercepting the system Again occasion, disable the onBackPressedCallback callback.


onBackPressedCallback.isEnabled = webView.canGoBack()

Be aware: Your app could require utilizing the platform APIs (OnBackInvokedCallback and OnBackPressedDispatcher) to implement the predictive again gesture. Learn our documentation for particulars.

Allow the developer choice to check the predictive again gesture

When you’ve up to date your app to help the predictive again gesture, you’ll be able to allow a developer choice (supported in Android 13 Beta 4 and better) to see it for your self.

To check this animation, full the next steps:

  1. In your machine, go to Settings > System > Developer choices.
  2. Choose Predictive again animations.
  3. Launch your up to date app, and use the again gesture to see it in motion.

Thanks once more for all of the suggestions and being part of the Android Group – we love collaborating collectively to supply the perfect expertise for our customers.


Most Popular