Android - How to stop animation between activity changes

前端 未结 5 2252
轮回少年
轮回少年 2020-12-15 17:28

I have multiple different Activity in my app and I don\'t want any transition animation when changing between Activities. Below is the how I\'m changing between Activities:

相关标签:
5条回答
  • 2020-12-15 18:00

    add this after creating the second intent

            Intent i = new Intent(SecondActivity.this, FirstActivity.class);
            i.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
            i.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
            startActivity(i);
    

    when you return to the first intent, animation is disabled, worked for me though

    0 讨论(0)
  • 2020-12-15 18:01

    Have you tried overridePendingTransition()?

    0 讨论(0)
  • 2020-12-15 18:04

    I wa needing this as I had to create activities on clicking the menus.

    I did the following :

    I added the FLAG_ACTIVITY_NO_ANIMATION flag to the intent. It stopped the animations while creating the activity for the first time.

    However the activities in the stack which were called when we click on the same menu again (probably from a different activity), it had the animation.

    So I added FLAG_ACTIVITY_NO_HISTORY to clear or rather finish the activity when it starts a new activity. This caused to create a new activity (without animation) when I click on the menu once again.

    0 讨论(0)
  • 2020-12-15 18:08

    You can set FLAG_ACTIVITY_REORDER_TO_FRONT by code and FLAG_ACTIVITY_NO_ANIMATION in manifest as below:

    Create noAnimTheme in res/values/styles.xml

    <style name="noAnimTheme" parent="android:Theme">
       <item name="android:windowAnimationStyle">@null</item>
    </style>
    

    or

    <style name="noAnimTheme" parent="android:Theme.NoTitleBar">
       <item name="android:windowAnimationStyle">@null</item>
    </style>
    

    and use it in manifest:

    <activity android:name="SecondActivity" android:theme="@style/noAnimTheme"/>
    

    I hope it helps

    0 讨论(0)
  • 2020-12-15 18:08

    If you're using FLAG_ACTIVITY_REORDER_TO_FRONT then you can also override onNewIntent for later startActivity calls. This will just work for bring to front states instead of first call.

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        overridePendingTransition(R.anim.whatever, R.anim.whatever);
    }
    

    Sure, you must implement this in target activity.

    0 讨论(0)
提交回复
热议问题