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 need 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 gained’t be seen to customers in Android 13, we’re making an early model of the UI accessible as a developer possibility for testing beginning in Beta 4. We plan to make the UI accessible 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 the way to check out the brand new gesture and assist it in your apps. Including assist for predictive again gesture is simple for many apps, and you may get began at the moment.
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 accessible by way of the developer possibility, you’ll have to first replace your app to assist the predictive again gesture, after which allow the developer possibility.
Replace your app to assist predictive again gesture
To assist make predictive again gesture useful and constant for customers, we’re shifting 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 easy as attainable.
The brand new platform APIs embody OnBackInvokedCallback
and OnBackInvokedDispatcher, which AndroidX Exercise 1.6+ helps by way of the present OnBackPressedCallback and OnBackPressedDispatcher
APIs.
You can begin testing this characteristic in two to 4 steps, relying in your current implementation.
To start testing this characteristic:
1. Improve to AndroidX Exercise 1.6.0-alpha05. By upgrading your dependency on AndroidX Exercise, APIs which are already utilizing the OnBackPressedDispatcher APIs reminiscent of Fragments and the Navigation Part will seamlessly work once you opt-in for the predictive again gesture.
2. Decide-in for the predictive again gesture. Decide-in your app by setting the EnableOnBackInvokedCallback flag to true on the software stage within the AndroidManifest.xml.
In case your app doesn’t intercept the again occasion, you are carried out at this step.
Word: Decide-in is non-obligatory in Android 13, and it will likely be ignored after this model.
3. Create a callback to intercept the system Again button/occasion. If attainable, we suggest utilizing the AndroidX APIs as proven beneath. For non-AndroidX use instances, examine the platform API talked about above.
This snippet implements handleOnBackPressed and provides the OnBackPressedCallback to the OnBackPressedDispatcher on the exercise stage.
4. When your app is able to cease intercepting the system Again occasion, disable the onBackPressedCallback callback.
Word: 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 possibility to check the predictive again gesture
When you’ve up to date your app to assist the predictive again gesture, you possibly can allow a developer possibility (supported in Android 13 Beta 4 and better) to see it for your self.
To check this animation, full the next steps:
- In your machine, go to Settings > System > Developer choices.
- Choose Predictive again animations.
- 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 one of the best expertise for our customers.