解决 Only fullscreen opaque activities can request orientation 特殊情况

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_31796651/article/details/86167277

 自己测试好的应用打包到测试,测试来了句你确定你的功能是好的,直接就回肯定没问题的,然后打脸了,她的手机一点就崩溃,果断拿手机过来调试,结果发现报下面的错误:

问题分析:百度了下,确定是android 8.0系统导致的问题;知道问题就好办了 

此问题只在android 8.0出现,在8.0以后google已经修改了这个问题;我已经适配到了android 9.0了,所以我的项目中没有类似代码;

网上找到26 activity中对应的代码:

@CallSuper
protected void onCreate(@Nullable Bundle savedInstanceState) {
        if (DEBUG_LIFECYCLE) Slog.v(TAG, "onCreate " + this + ": " + savedInstanceState);

        if (getApplicationInfo().targetSdkVersion >= O && mActivityInfo.isFixedOrientation()) {
            final TypedArray ta = obtainStyledAttributes(com.android.internal.R.styleable.Window);
            final boolean isTranslucentOrFloating = ActivityInfo.isTranslucentOrFloating(ta);
            ta.recycle();

            if (isTranslucentOrFloating) {
                throw new IllegalStateException(
                        "Only fullscreen opaque activities can request orientation");
            }
 }

简单来说:当前activity不是全屏或是透明主题不能锁定页面方向;

                 我的页面正好做了特殊转场动画,出现黑屏问题,又添加了透明主题,然后就碰巧遇到问题了;

解决方法:1、不要设置透明主题,或者将透明主题设置为false


<style name="MyAppTheme" parent="AppTheme">
    <item name="android:windowIsTranslucent">false</item>
</style>

2、自己设置了转场动画,不设置透明主题会出现短暂黑屏问题:

//你是不是这样设置的进入动画呢
overridePendingTransition(R.anim.activity_bottom_to_top, 0);
//改为这样,即使不设置透明主题也不会出现黑屏问题
overridePendingTransition(R.anim.activity_bottom_to_top, R.anim.anim_no);

没有动画anim_no.xml文件

//使用这个无动画
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
//动画时常和你正常动画时常一致,动画只供参考
    <translate
        android:duration="350"
        android:fromYDelta="0"
        android:interpolator="@android:anim/decelerate_interpolator"
        android:toYDelta="0" />
</set>


//不要使用这个===为了说明,网上有人说使用这样,结果测试了下黑屏问题存在
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
     android:duration="0">
</set>

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------

以下是我的公众账号,来看看是不是你喜欢的菜:

猜你喜欢

转载自blog.csdn.net/qq_31796651/article/details/86167277
今日推荐