6

I have been trying to disable the animation of my activity when calling moveTaskToBack(). I am testing on my Nexus 7 on Marshmallow, and no matter what I do, the "sliding down" animation is still there.

Things that I have tried:

  • Calling overridePendingTransition(0, 0); after moveTaskToBack()
  • Calling overridePendingTransition(0, 0); in onDestroy() and onPause()
  • Calling getWindow().setWindowAnimations(0); in the above places
  • Create a custom style for the activity with the following:

.

<item name="android:windowAnimationStyle">@null</item>
<item name="android:windowExitAnimation">@null</item>
<item name="android:activityOpenEnterAnimation">@null</item>
<item name="android:activityOpenExitAnimation">@null</item>
<item name="android:activityCloseEnterAnimation">@null</item>
<item name="android:activityCloseExitAnimation">@null</item>

None of the above and their combination work. I am out of idea. Can someone help me out please?

Chin
  • 19,717
  • 37
  • 107
  • 164
  • 1
    Try this: startActivity(new Intent(FirstActivity.this,SecondActivity.class)); overridePendingTransition(0, 0); OR try this link: [link1](http://stackoverflow.com/questions/6972295/switching-activities-without-animation/9312957#9312957) [link2](http://stackoverflow.com/questions/2286315/disable-activity-slide-in-animation-when-launching-new-activity) – YLS Dec 07 '15 at 07:36
  • I tried all of that, as you can see in my question – Chin Dec 07 '15 at 16:01
  • @Chin : were you able to find a solution for this? I am currently stuck on the same problem. – Swayam Nov 30 '17 at 14:35
  • @Swayam I never found a solution to this, unfortunately – Chin Nov 30 '17 at 15:25

2 Answers2

0

I have faced with this, this can help

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == android.R.id.home) {
        onBackPressed();
        return true;
    }
    return super.onOptionsItemSelected(item);

}

@Override
public void onBackPressed() {
    finish();
    overridePendingTransition(0, 0);
}
Dennis Zinkovski
  • 1,821
  • 3
  • 25
  • 42
0

I accidentally need this too.
I'm good with the result of following settings

<style name="noAnimation">
    <item name="android:activityOpenEnterAnimation">@null</item>
    <item name="android:activityOpenExitAnimation">@null</item>
    <item name="android:activityCloseEnterAnimation">@null</item>
    <item name="android:activityCloseExitAnimation">@null</item>
    <item name="android:taskOpenEnterAnimation">@null</item>
    <item name="android:taskOpenExitAnimation">@null</item>
    <item name="android:taskCloseEnterAnimation">@null</item>
    <item name="android:taskCloseExitAnimation">@null</item>
    <item name="android:taskToFrontEnterAnimation">@null</item>
    <item name="android:taskToFrontExitAnimation">@null</item>
    <item name="android:taskToBackEnterAnimation">@null</item>
    <item name="android:taskToBackExitAnimation">@null</item>
</style>

// then overwrite theme with style above.

<style name="Theme.noAnimation" parent="Theme.MaterialComponents.DayNight.NoTitleBar">
    <item name="android:windowAnimationStyle">@style/noAnimation</item>
</style>

Hope this could help others who need this :)

hoso.ch
  • 248
  • 2
  • 8