java.lang.IllegalStateException: Only fullscreen opaque activities can request orientation
In android Oreo (API 26) you can not change orientation for Activity that have below line(s) in style
<item name="android:windowIsTranslucent">true</item>
or
<item name="android:windowIsFloating">true</item>
You have several way to solving this :
1) You can simply remove above line(s) (or turn it to false) and your app works fine.
2) Or you can first remove below line from manifest for that activity
android:screenOrientation="portrait"
Then you must add this line to your activity (in onCreate())
//android O fix bug orientation
if (android.os.Build.VERSION.SDK_INT != Build.VERSION_CODES.O) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
3) You can create new styles.xml
in values-v26
folder and add this to your style.xml
. (Thanks to AbdelHady comment)
<item name="android:windowIsTranslucent">false</item>
<item name="android:windowIsFloating">false</item>
In Android O and later this error happens when you set
android:screenOrientation="portrait"
in Manifest.
Remove that line and use
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
in your activity.
This will fix your issue.
Google throws this exception on Activity's onCreate
method after v27, their meaning is : if an Activity is translucent or floating, its orientation should be relied on parent(background) Activity, can't make decision on itself.
Even if you remove android:screenOrientation="portrait"
from the floating or translucent Activity but fix orientation on its parent(background) Activity, it is still fixed by the parent, I have tested already.
One special situation : if you make translucent on a launcher Activity, it has't parent(background), so always rotate with device. Want to fix it, you have to take another way to replace <item name="android:windowIsTranslucent">true</item>
style.