184

How can I use properly the Intent flag FLAG_ACTIVITY_NO_ANIMATION in AndroidManifest file? I supose my problem is trivial, but I can't find good example or solution to it.

    <intent-filter>
        <data android:name="android.content.Intent.FLAG_ACTIVITY_NO_ANIMATION" />
    </intent-filter>

However no error is reported by compliator, but data isn't correct. I just want to disable animation in case switching between activities. I can use getWindow().setWindowAnimations(0); in onCreate or onResume rather but using flag is better way, isn't it?

I can use also in code:

    Intent intent = new Intent(v.getContext(), newactivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
    getContext().startActivity(intent);

But I want to use this flag in Android Manifest. To disable animation also in case returning from second activity to first.

sonique
  • 4,539
  • 2
  • 30
  • 39
woyaru
  • 5,544
  • 13
  • 54
  • 92
  • I have found the sugestion to use theme - by defining enter, exit animations for activities or entire application. Can someone give me more informations about it? – woyaru Aug 07 '11 at 11:59

9 Answers9

296

You can create a style,

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

and set it as theme for your activity in the manifest:

   <activity android:name=".ui.ArticlesActivity" android:theme="@style/noAnimTheme">
    </activity>

You can also define a style to specify custom entry and exit animations. http://developer.android.com/reference/android/R.attr.html#windowEnterAnimation

Santosh
  • 13,251
  • 5
  • 24
  • 12
  • Thanks, this works just great especially for transparent/dialog themed activities excluded from recents with a different task affinity. Without this the animation kept showing creating very odd results for a dialog being opened! – 3c71 Oct 05 '13 at 08:54
  • 1
    this no longer seems to work for Lollipop/Android 5.0? – kenyee Mar 23 '15 at 16:25
  • I have Android 5 and it works for me. My app style looks like this: – eatyourgreens May 26 '15 at 06:00
  • Works perfectly in 6.0 also. A great tip. As I ask below, I wonder how to disable the animation which happens when ***first launching an app** ... is there a way ?! – Fattie Nov 27 '16 at 16:15
  • 5
    will crash if you extend AppCompatActivity – Mike6679 Mar 27 '17 at 16:34
218

If your context is an activity you can call overridePendingTransition:

Call immediately after one of the flavors of startActivity(Intent) or finish to specify an explicit transition animation to perform next.

So, programmatically:

this.startActivity(new Intent(v.getContext(), newactivity.class));
this.overridePendingTransition(0, 0);
Muhammed Refaat
  • 8,914
  • 14
  • 83
  • 118
eshirazi
  • 2,773
  • 1
  • 14
  • 13
58

Try this code,

this.startActivity(new Intent(v.getContext(), newactivity.class).addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION));
Lucifer
  • 29,392
  • 25
  • 90
  • 143
29

You can also just do this in all the activities that you dont want to transition from:

@Override
public void onPause() {
    super.onPause();
    overridePendingTransition(0, 0);
}

I like this approach because you do not have to mess with the style of your activity.

  • A great tip. I wonder how to disable the animation which happens when ***first launching an app** ... is there a way ?! – Fattie Nov 27 '16 at 16:13
  • @Fattie Override the onStart() method of your launching activity and place the same code in that. –  Apr 08 '20 at 06:16
11

The line in the theme style works fine, yet that replaces the animation with a white screen. Especially on a slower phone - it is really annoying. So, if you want an instant transition - you could use this in the theme style:

<item name="android:windowAnimationStyle">@null</item>
<item name="android:windowDisablePreview">true</item>
7

Here is a one-liner solution that works for as low as minSdkVersion 14 which you should insert in you res/styles.xml:

<item name="android:windowAnimationStyle">@null</item>

like so:

<resources>
    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        ...
        <item name="android:windowAnimationStyle">@null</item>
    </style>
    ...
</resources>

Cheers!

user1506104
  • 6,554
  • 4
  • 71
  • 89
6

After starting intent you can use this code :

Intent intent = new Intent(Activity1.this, Activity2.class);
overridePendingTransition(0, 0);
intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
startActivity(intent);

If used, intent will work with no animations or transitions

Faran
  • 59
  • 1
  • 6
  • overridePendingTransition seems like it won't do anything since there is no transition pending when the function is called. I added the flag for no animation to my code and it worked as expected (without needing the override). – David Rector Dec 13 '22 at 18:30
5

This is not an example use or an explanation of how to use FLAG_ACTIVITY_NO_ANIMATION, however it does answer how to disable the Activity switching animation, as asked in the question title:

Android, how to disable the 'wipe' effect when starting a new activity?

Community
  • 1
  • 1
Phil
  • 35,852
  • 23
  • 123
  • 164
2

create your own style overriding android:Theme

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

Then use it in manifest like this:

<activity android:name=".MainActivity"
    android:theme="@style/noAnimationStyle">
</activity>
goyo
  • 39
  • 7