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())

'>=' change to '!=' thanks to Entreco comment

    //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.


The problem seems to be happening when your target sdk is 28. So after trying out many options finally this worked.

<activity
            android:name=".activities.FilterActivity"
            android:theme="@style/Transparent"
            android:windowSoftInputMode="stateHidden|adjustResize" />

style:-

<style name="Transparent" parent="Theme.AppCompat.Light.NoActionBar">
     <item name="android:windowIsTranslucent">true</item>
     <item name="android:windowBackground">@android:color/transparent</item>
     <item name="android:windowIsFloating">true</item>
     <item name="android:windowContentOverlay">@null</item>
     <item name="android:windowNoTitle">true</item>
     <item name="android:backgroundDimEnabled">false</item>
 </style>

Note:parent="Theme.AppCompat.Light.NoActionBar" is needed for api 28. Previously had something else at api 26. Was working great but started to give problem at 28. Hope it helps someone out here. EDIT: For some only by setting <item name="android:windowIsTranslucent">false</item> and <item name="android:windowIsFloating">false</item> worked.May be depends upon the way you implement the solution works.In my case it worked by setting them to true.


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:

android:screenOrientation="portrait"

your translucent activity will have the same orientation lock: portrait.