IllegalStateException: Only fullscreen opaque acti

2019-01-15 01:47发布

问题:

I have an activity that open from browser when Device is in Landscape get me below error

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

Manifest

<activity android:name=".Activity.MyActivity"
        android:configChanges="orientation"
        android:screenOrientation="portrait"
        android:theme="@style/AppTheme.Theme_Slide"
        >
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />

            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />

            <data
                android:host="xxx"
                android:scheme="xxx" />
            <data
                android:host="xxx"
                android:scheme="xxx" />
        </intent-filter>
    </activity>

style.xml

<style name="AppTheme.Theme_Slide" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="android:windowIsTranslucent">true</item>
    <item name="android:windowCloseOnTouchOutside">false</item>
</style>

回答1:

UPDATE FINDED SOLUTION

in android Oreo, you can not change orientation for Activity that has

 <item name="android:windowIsTranslucent">true</item>

in the style. you must first remove below line from the manifest

android:screenOrientation="portrait"

secondly, you must add this line to java file

    //android O fix bug orientation
    if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    }