zoukankan      html  css  js  c++  java
  • Only fullscreen activities can request orientation

    问题

    当我们把targetSdkVersion升级到27,buildToolsVersion和相关的support library升级到27.0.2后,在Android 8.0(API level 26)上,Activity出现了一个莫名其妙的crash,异常信息如下:

    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.xxx.xxx/com.xxx.xxx.WelcomeActivity}: java.lang.IllegalStateException: Only fullscreen opaque activities can request orientation
    
    原因

    这个问题出现在Api 26上,抛出异常的代码:

    if (ActivityInfo.isFixedOrientation(requestedOrientation) 
        && !fullscreen
        && appInfo.targetSdkVersion >= O) {
        throw new IllegalStateException("Only fullscreen activities can request orientation");
    }
    

    意思就是只有不透明的全屏activity可以自主设置界面方向。我们的启动页面Activity在style设置和在Manifset.xml设置下面属性导致抛出异常。

    <item name="android:windowIsTranslucent">true</item>
    android:screenOrientation="portrait"
    
    修复

    删除AndroidManifest中相应Activity的 android:screenOrientation=""属性;或者删除相应Activity的theme中true属性。但如果想保留screenOrientation,那么需要去除启动页白屏和黑屏的效果。

  • 相关阅读:
    js 实现继承的6种方式(逐渐优化)
    http2.0 特性
    http 206请求
    http put post请求区别
    stopPropagation 和stopImmediatePropagation区别
    JavaScript事件流
    BFC特性 形成BFC
    元素高度、宽度获取 style currentStyle getComputedStyle getBoundingClientRect
    三栏布局解决方案
    jquery vue 框架区别
  • 原文地址:https://www.cnblogs.com/fomin/p/8693663.html
Copyright © 2011-2022 走看看