Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Oreo: disable Activity transition animation

I need to disable Activity transition animation for all the screens in my application. Previous solution worked fine for all Android version:

<style name="base_theme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="android:windowAnimationStyle">@null</item>
</style>

... but for Android 8 "Oreo" it cause black screen blinking for every transition (forward or back move). I.e. there is still no any animation, but very annoying blinking take place (90% chance, ~20-30 milliseconds, the whole screen).

According to my "research":

  • it does not depends on activity content and reproduced with empty activities
  • there is no any background work which could slow down the transition process
  • Intent.FLAG_ACTIVITY_NO_ANIMATION blinks as well
  • overridePendingTransition(0,0) doesn't work too

The only solution I could find:

Define an empty transition animation

<?xml version="1.0" encoding="utf-8"?>
<set />

and apply it to every activity in the application (onCreate & finish)

overridePendingTransition(R.anim.animation_activity_none, R.anim.animation_activity_none);

Question:

Is it some kind of new restrictions for Oreo (i.e. feature), or platform bug, or maybe the application issue? Are there any other solutions?

[UPDATE]

One more finding. Make sure you call Activity finish() and overridePendingTransition() pair on the main thread! Otherwise thread race happens and overridePendingTransition not applied sometimes.

[UPDATE]

Google has confirmed it's a bug in Android 8.0, presumably fixed in 8.1. So the "empty animation" fix is for years, until minSdkVersion == 27.

like image 673
Sergey Krivenkov Avatar asked Sep 25 '17 09:09

Sergey Krivenkov


1 Answers

I had the same issue, and I managed to solve it, the idea is to play nothing, please see the xml below:

Values folder

<style name="yourTheme">
    <item name="android:windowAnimationStyle">@style/ThemeApp.Animation.Activity.Replace</item>

<style name="ThemeApp.Animation.Activity.Replace">
    <item name="android:activityOpenEnterAnimation">@anim/replace_anim</item>
    <item name="android:activityOpenExitAnimation">@anim/replace_anim</item>
    <item name="android:activityCloseEnterAnimation">@anim/replace_anim</item>
    <item name="android:activityCloseExitAnimation">@anim/replace_anim</item>
    <item name="android:taskOpenEnterAnimation">@anim/replace_anim</item>
    <item name="android:taskOpenExitAnimation">@anim/replace_anim</item>

Anim folder: replace_anim.xml

<set/>
like image 140
Mike Kuasinski Avatar answered Oct 27 '22 16:10

Mike Kuasinski