Oreo: disable Activity transition animation

落爺英雄遲暮 提交于 2020-01-01 10:35:07

问题


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.


回答1:


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/>


来源:https://stackoverflow.com/questions/46401883/oreo-disable-activity-transition-animation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!