Activity transition using overrideActivityTransition doesn't work in Android 34

1.1k views Asked by At

I am using overridePendingTransition to make a transition from MainActivity to a Sub-Activity. The transition moves MainActivty out on the right, and the Sub-Activity into the screen from the left.

I need that the transition is triggered by pressing a button and not started by back pressed.

overridePendingTransition(R.anim.slide_in_left,R.anim.slide_out_right);

After change to overrideActivityTransition above transition doesn't work for Android >=34.

overrideActivityTransition(OVERRIDE_TRANSITION_OPEN,R.anim.slide_in_left,R.anim.slide_out_right);

How can i restore the behaviour under Android 34?

Thanks GGK

1

There are 1 answers

1
J.Son On

The overrideActivityTransition isn't fully compatible with the previous overridePendingTransition method.
You should call the overrideActivityTransition inside your Sub-Activity's onCreate() method:

if (Build.VERSION.SDK_INT >= 34) {
    overrideActivityTransition(
        Activity.OVERRIDE_TRANSITION_OPEN,
        R.anim.slide_in_left,
        R.anim.slide_out_right,
        Color.TRANSPARENT
    )
}

For further explanation, look at the documentation: https://developer.android.com/about/versions/14/features/predictive-back#custom-activity