The primary milestone is to improve to Kotlin 1.8.0 or larger, which is required for different Predictive Again dependencies.
Again-to-home animation milestone
The back-to-home animation is the keystone predictive again animation.
To get this animation, add android:enableOnBackInvokedCallback=true
in your AndroidManifest.xml
to your root exercise in case you are a multi-activity app (see per-activity opt-in) or on the utility degree in case you are a single-activity app. After this, you’ll see each the back-to-home animation and a cross-task animation the place relevant, that are seen to customers in Android 15+ and behind a developer possibility in Android 13 and 14.
If you’re intercepting again occasions in your root exercise (e.g. MainActivity), you’ll be able to proceed to take action however you’ll want to make use of supported APIs and also you received’t get the back-to-home animation. For that reason, we usually advocate you solely intercept again occasions for UI logic; for instance, to point out a dialog asking the consumer to avoid wasting earlier than they give up.
See the Add help for the predictive again gesture information for extra particulars.
Migrate all actions milestone
If you’re a multi-activity app, you’ll must opt-in and deal with again occasions inside these actions too to get a system managed cross-activity animation. Be taught extra about per-activity opt-in, out there for gadgets working Android 14+. The cross-activity animation is seen to customers in Android 15+ and behind a developer possibility in Android 13 and 14.
Customized cross exercise animations are additionally out there with overrideActivityTransition.
Fragment milestone
Subsequent, you’ll need to focus in your fragment animations and transitions. This requires updating to AndroidX fragment 1.7.0 and transition 1.5.0 or later and utilizing Animator or AndroidX Transitions. Assuming these necessities are met, your current fragment animations and transitions will animate consistent with the again gesture. You too can use materials movement with fragments. Most materials motions help predictive again as of 1.12.02-alpha02 or larger, together with MaterialFadeThrough, MaterialSharedAxis and MaterialFade.
Don’t try to make your fragment transitions appear to be the system’s cross-activity transition. We advocate this full display screen floor transition as a substitute.
Be taught extra about Fragments and Predictive Again.
Materials Parts milestone
Lastly, you’ll need to reap the benefits of the Materials Part View animations out there for Predictive Again. Be taught extra about out there parts.
After this, you’ve accomplished your quest to help Predictive Again animations in your view based mostly app.
[Optional] AndroidX Transitions milestone
When you’re up for extra, you may additionally guarantee your AndroidX transitions are supported with Predictive Again. Learn extra about AndroidX Transitions and the Predictive Again Progress APIs.