Search code examples
androidanimationandroid-activitytransition

Is android:windowExitAnimation not working?


As mentioned by Google in this https://youtu.be/N_x7SV3I3P0

view.animation is still the way for Windows transition Animation.

Hence I use

    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <item name="android:windowAnimationStyle">@style/WindowAnimations</item>
    </style>

    <style name="WindowAnimations">
        <item name="android:windowEnterAnimation">@anim/enter_activity</item>
        <item name="android:windowExitAnimation">@anim/exit_activity</item>
    </style>

I only get the enter transition when I get from Activity1 (Hello World) to Activitity2 (Purple). Similar when getting back from Activity2 to Activitiy1, only the enter transition shown. The exit transition can never be triggered.

Shown below is the result.

enter image description here

Looks like android:windowExitAnimation is not working? (i.e. if I remove it, the effect is the same).

To workaround, in my Activity2, I use overridePendingTransition(R.anim.enter_activity, R.anim.exit_activity) instead like below.

class Main2Activity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main2)
        overridePendingTransition(R.anim.enter_activity, R.anim.exit_activity)
    }

    override fun finish() {
        super.finish()
        overridePendingTransition(R.anim.enter_activity, R.anim.exit_activity)
    }
}

Then I get the result as I wanted.

enter image description here

Is there a bug in android:windowExitAnimation? Or I miss something?


p/s: my transition animation XML as below

enter_activity.xml

<set android:shareInterpolator="false"
    xmlns:android="http://schemas.android.com/apk/res/android">
    <scale
        android:interpolator="@android:anim/accelerate_decelerate_interpolator"
        android:fromXScale="0.0"
        android:toXScale="1.0"
        android:fromYScale="0.0"
        android:toYScale="1.0"
        android:pivotX="50%"
        android:pivotY="50%"
        android:fillAfter="false"
        android:duration="2000" />
</set>

exit_activity.xml

<set android:shareInterpolator="false"
    xmlns:android="http://schemas.android.com/apk/res/android">
    <scale
        android:interpolator="@android:anim/accelerate_decelerate_interpolator"
        android:fromXScale="1.0"
        android:toXScale="0.0"
        android:fromYScale="1.0"
        android:toYScale="0.0"
        android:pivotX="50%"
        android:pivotY="50%"
        android:fillAfter="false"
        android:duration="2000" />
</set>

Solution

  • Looks like I need to use the below instead

    <style name="WindowAnimations">
        <item name="android:activityOpenEnterAnimation">@anim/enter_activity</item>
        <item name="android:activityOpenExitAnimation">@anim/exit_activity</item>
        <item name="android:activityCloseEnterAnimation">@anim/enter_activity</item>
        <item name="android:activityCloseExitAnimation">@anim/exit_activity</item>
    </style>
    

    The below is supposed to use for opening up the App or close the App (or background the App), and not for opening different Android Activities (although it is strange that android:windowEnterAnimation works for opening activity, and will interfere (mixed) with the android:activityOpenEnterAnimation and android:activityCloseEnterAnimation)

    <style name="WindowAnimations">
        <item name="android:windowEnterAnimation">@anim/enter_activity</item>
        <item name="android:windowExitAnimation">@anim/exit_activity</item>
    </style>
    

    The windowEnterAnimation works but not windowExitAnimation though.