Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
266 views
in Technique[技术] by (71.8m points)

java - Lock screen orientation when targeting Android API 27 with a non-opaque activity

I have an activity that has android:windowIsTranslucent set to true and android:windowBackground set to a translucent background. I just changed my target and compile sdk version to 27, and I get an exception when launching this activity now:

java.lang.IllegalStateException: Only fullscreen opaque activities can request orientation

Since this is a new sdk, there isn't anything online about it yet (and it seems to result from this line of code: https://android.googlesource.com/platform/frameworks/base.git/+/master/core/java/android/app/Activity.java#987 )

Is there any way to get around this? The app doesn't crash if I take out android:screenOrientation="portrait" from my manifest for this activity, but I would like to be able to keep it like that.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I also faced the same problem. As others said, If I deleted android:screenOrientation="portrait" or overrided it with android:screenOrientation="unspecified", then the exception was gone. And it seems that the front activity's orientation follows the behind activity's orientation.

I thought about it. If the front activity is transparent and the behind activity's orientation is different, the display becomes strange. So, I can understand why this check logic was added However, I wonder that why this problem was not occurred in Developer Preview 8.0.0.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...