zoukankan      html  css  js  c++  java
  • Only fullscreen opaque activities can request orientation 原因及解决方案

    今天在三星S8上遇见一个奇葩问题Only fullscreen opaque activities can request orientation

    一、出现场景

    • 三星手机S8 android 8.0
    • targetSdkVersion 27
    • 透明Activity

    二、解决方案

    manifest中移除android:screenOrientation="portrait"

    三、原因(源码中寻找)

    查看Android 8.0源码

    3.1、ActivityRecord#setRequestedOrientation

    Alt text

    有几个条件:

    • 非全屏 !fullscreen
    • targetSdkVersion的设置为大于26 appInfo.targetSdkVersion > O
    • ActivityInfo.isFixedOrientation(requestedOrientation)

    所以下边来跟踪一下ActivityInfo.isFixedOrientation(requestedOrientation)

    3.2、跟踪ActivityInfo.isFixedOrientation(requestedOrientation)

    在这里插入图片描述

    继续跟踪isFixedOrientationPortrait(int orientation)

    在这里插入图片描述

    最后的原因找到了,就是因为orientation == SCREEN_ORIENTATION_PORTRAIT

    3.3、总结一下

    • 如果一个 targetSdkVersion>26的Android App
    • 运行在Android 8.0(含) 以上的设备上时
    • 如果启动的Activity为透明Activity

    screenOrientation 需为默认状态

    四、Google为什么这么做?

    stackoverflow 中看到一句话。

    这句话,我在google官方文档上并没有找到依据,但经过我的验证是正确的

    If you use a fullscreen transparent activity, there is no need to specify the orientation lock on the activity. It will take the configuration settings of the parent activity. So if the parent activity has in the manifest:

    这种情况下,透明Activity使用的是栈中,上一层可见Activity的orientation设定。仔细想一想是合理的,因此这并不是一个bug。

    五、最后重申一遍解决方案

    综上所述,移除android:screenOrientation="portrait" 的解决方案,完全符合Google的设计本意,并非Bug

    ========== THE END ==========

    wx_gzh.jpg

  • 相关阅读:
    Visual Studio Reference Study.
    A Sample of communication between two processes
    BLE GATT 介绍
    BLE广播数据包分析
    geekuninstaller官方下载
    keil软件异常
    iBeacon data format
    Advertising and Scan Response Data Format
    Eclipse指定项目文件夹里.metadata文件夹的作用
    you must restart adb and eclipse的相关解决办法
  • 原文地址:https://www.cnblogs.com/xiaxveliang/p/12396098.html
Copyright © 2011-2022 走看看