Disable activity slide-in animation when launching new activity?

Android

Android Problem Overview


I have an activity which launches another activity, via a button click. By default, on newer OS versions of android, the OS will animate the new activity sliding in from right to left.

Is there a way to disable this animation? I just want the new activity to appear without any sort of animation.

Android Solutions


Solution 1 - Android

The FLAG_ACTIVITY_NO_ANIMATION flag works fine for disabling the animation when starting activities.

To disable the similar animation that is triggered when calling finish() on an Activity, i.e the animation slides from right to left instead, you can call overridePendingTransition(0, 0) after calling finish() and the next animation will be excluded.

This also works on the in-animation if you call overridePendingTransition(0, 0) after calling startActivity(...).

Solution 2 - Android

IMHO this answer here solve issue in the most elegant way..

Developer should create a style,

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

then in manifest set it as theme for activity or whole application.

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

Voila! Nice and easy..

P.S. credits to original author please

Solution 3 - Android

Apply

startActivity(new Intent(FirstActivity.this,SecondActivity.class));

then

overridePendingTransition(0, 0);

This will stop the animation.

Solution 4 - Android

In my opinion the best answer is to use "overridePendingTransition(0, 0);"

to avoid seeing animation when you want to Intent to an Activity use:

this.startActivity(new Intent(v.getContext(), newactivity.class));
this.overridePendingTransition(0, 0);

and to not see the animation when you press back button Override onPause method in your newactivity

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

Solution 5 - Android

Just specify Intent.FLAG_ACTIVITY_NO_ANIMATION flag when starting

Solution 6 - Android

This works for me when disabling finish Activity animation.

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

Solution 7 - Android

I'm on 4.4.2, and calling overridePendingTransition(0, 0) in the launching activity's onCreate() will disable the starting animation (calling overridePendingTransition(0, 0) immediately after startActivity() did NOT work). As noted in another answer, calling overridePendingTransition(0, 0) after finish() disables the closing animation.

Btw, I found that setting the style with "android:windowAnimationStyle">@null (another answer mentioned here) caused a crash when my launching activity tried to set the action bar title. Debugging further, I discovered that somehow this causes window.hasFeature(Window.FEATURE_ACTION_BAR) to fail in the Activity's initActionBar().

Solution 8 - Android

FLAG_ACTIVITY_NO_ANIMATION may work, but wasn't doing the trick for me when combined with FLAG_ACTIVITY_CLEAR_TASK and FLAG_ACTIVITY_NEW_TASK. I'm apparently seeing the animation for creating a new task with a fresh activity stack as I navigate laterally to my other top-level views.

What did work here was calling "overridePendingTransition(0, 0);" either immediately after my startActivity() call or the onPause(). Both ways worked, but doing it after startActivity() gives me a little more control over when I want animations and when I don't.

Solution 9 - Android

I had a similar problem of getting a black screen appear on sliding transition from one activity to another using overridependingtransition. and I followed the way below and it worked

  1. created a noanim.xml in anim folder

    http://schemas.android.com/apk/res/android" android:duration="@android:integer/config_longAnimTime" android:fromYDelta="0%p" android:toYDelta="0%p" />

and used

overridePendingTransition(R.drawable.lefttorightanim, R.anim.noanim);

The first parameter as my original animation and second parameter which is the exit animation as my dummy animation

Solution 10 - Android

In order to avoid the black background when starting an activity already in the stack, I added overridePendingTransition(0,0) in onStart():

@Override
protected void onStart() {
    overridePendingTransition(0,0);
    super.onStart();

}

Solution 11 - Android

To clear things up: FLAG_ACTIVITY_NO_ANIMATION (or android:windowAnimationStyle = @null in the theme) work perfectly fine for both, enter and exit. The problem is, that the enter animation checks if the animation is enabled in the one activity and the exit animation checks it for the other one. So make sure to disable it in both activities.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser246114View Question on Stackoverflow
Solution 1 - AndroidMattiasView Answer on Stackoverflow
Solution 2 - AndroidEwoksView Answer on Stackoverflow
Solution 3 - AndroidSiddharth_VyasView Answer on Stackoverflow
Solution 4 - AndroidSasaView Answer on Stackoverflow
Solution 5 - AndroidAlexander KosenkovView Answer on Stackoverflow
Solution 6 - AndroidcmcromanceView Answer on Stackoverflow
Solution 7 - AndroidSteve BView Answer on Stackoverflow
Solution 8 - AndroidWookieView Answer on Stackoverflow
Solution 9 - AndroidKarthika PBView Answer on Stackoverflow
Solution 10 - AndroidAlex HuiculescuView Answer on Stackoverflow
Solution 11 - AndroidCactusrootView Answer on Stackoverflow