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 growing 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 out there as a developer choice for testing beginning in Beta 4. We plan to make the UI out there 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 right way to check out the brand new gesture and help it in your apps. Including help for predictive again gesture is easy for many apps, and you will 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 out there via 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.
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 resembling Fragments and the Navigation Element will seamlessly work whenever 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 degree within the AndroidManifest.xml.
In case your app doesn’t intercept the again occasion, you are achieved at this step.
Notice: Decide-in is non-compulsory in Android 13, and it is going to 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 circumstances, test the platform API talked about above.
This snippet implements handleOnBackPressed and provides the OnBackPressedCallback to the OnBackPressedDispatcher on the exercise degree.
4. When your app is able to cease intercepting the system Again occasion, disable the onBackPressedCallback callback.
Notice: 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:
- In your gadget, 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 the perfect expertise for our customers.