overridePendingTransition is deprecated, how do i do?
Asked Answered
C

3

10

There is an animation playing when i finish a child activity or when the main one resume, im not sure which event is triggering it but i would like to replace it. Im targeting api level 34 with a min level of 28.

Im currently using

val intent = Intent(this, SettingsActivity::class.java)
val anim = ActivityOptions.makeCustomAnimation(
     applicationContext,
     R.anim.right_slide_in, R.anim.none
).toBundle()
startActivity(intent, anim)

I want to play an animation starting an activity but this did not help when I try to resume a parent activity or finish a child activity (again idk in which of these two cases the animation happens)

ChatGPT gave me some "solutions" with startAnimation on the rootView but nothing happens (and it also dont understand the word deprecated so its impossible to correct itself)

Carreon answered 5/11, 2023 at 13:27 Comment(0)
E
8

Starting API 34 , you have to use overrideActivityTransition , here is the official documentation to how to use it .

Evadne answered 5/11, 2023 at 22:58 Comment(3)
'Call requires API level 34 (current min is 28)'. If I just want to fix overridePendingTransition(0, 0), what should I do?Wenona
@Wenona check the Build.VERSION.SDK_INT value, if its 34 use overrideActivityTransition else use overridePendingTransitionCarreon
What about with finish()?Larine
A
3

Follow the below step this is how we do pending transition now.

val enterAnim = R.anim.activity_bottom_in
val exitAnim = R.anim.activity_stay
// Create a bundle for animation options
val options = ActivityOptionsCompat.makeCustomAnimation(requireContext(), enterAnim, exitAnim)
yourActivityLauncher.launch(getActivityIntent(), options)
Angloindian answered 1/3, 2024 at 20:27 Comment(0)
R
0

In Android API Level 34 (UPSIDE_DOWN_CAKE), overridePendingTransition has been deprecated. You should now use overrideActivityTransition.

Here's how to update your code:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
    overrideActivityTransition(OVERRIDE_TRANSITION_OPEN, R.anim.slide_enter, R.anim.slide_exit)
} else {
    overridePendingTransition(R.anim.slide_enter, R.anim.slide_exit)
}

overrideActivityTransition offers additional flexibility, allowing you to specify the overrideType (either OVERRIDE_TRANSITION_OPEN or OVERRIDE_TRANSITION_CLOSE), the enterAnim and exitAnim resources, and optionally, a backgroundColor.

For more details official documentation

Robi answered 12/8, 2024 at 12:43 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.