崩溃产生前提条件:
当 targetSdkVersion 为27时,且运行在 8.0的机器上时,运行在8.0以下的机器不会报错,或者targetSdkVersion修改为27以下也不会报错。
崩溃场景还原:
不管Activity是不是全屏,只要在Activity中设置竖屏:
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
并且 Acitivity的 Theme 中有
<item name ="android:windowIsTranslucent">true</item>
崩溃是什么
就会报下面这个错误,导致崩溃。
com.jianyifu.demo.MainActivity}: java.lang.IllegalStateException: Only fullscreen activities can request orientation
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2817)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)