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

前端 未结 30 1476
难免孤独
难免孤独 2020-12-02 04:43

I am facing the problem while retrieving the contacts from the contact book in Android 8.0 Oreo java.lang.IllegalStateException: Only fullscreen opaque activities can reques

相关标签:
30条回答
  • 2020-12-02 05:30

    I used android:screenOrientation="behind" instead of android:screenOrientation="portrait". Basically, you created a dialog (in an activity) and dialog can't request orientation by itself it needs parent activity to do this (because a parent is visible in the background and has own layout).

    "behind" The same orientation as the activity that's immediately beneath it in the activity stack.

    0 讨论(0)
  • 2020-12-02 05:31

    in the manifest file set second activity parentActivityName as first activity and remove the screenOrientation parameter to the second activity. it means your first activity is the parent and decide to an orientation of your second activity.

    <activity
            android:name=".view.FirstActiviy"
            android:screenOrientation="portrait"
            android:theme="@style/AppTheme" />
    
    <activity
            android:name=".view.SecondActivity"
            android:parentActivityName=".view.FirstActiviy"
            android:theme="@style/AppTheme.Transparent" />
    
    0 讨论(0)
  • 2020-12-02 05:31

    If you haven't resolved your problem just register the ad activity in the manifest like this:

    <activity
    android:name="com.google.android.gms.ads.AdActivity"
    android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
    tools:replace="android:theme"
     />
    

    You also need to update to the latest version of the sdk.

    0 讨论(0)
  • 2020-12-02 05:32

    I can't agree to most rated answer, because

    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    

    causes an error

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

    but this makes it works for me

    <style name="TranslucentTheme" parent="@style/Theme.AppCompat.Light.NoActionBar">
        <item name="android:windowNoTitle">true</item>
        <item name="android:windowActionBar">false</item>
        <item name="android:windowFullscreen">true</item>
        <item name="android:windowContentOverlay">@null</item>
    </style>
    

    and use it for your Activity, when you extends from

    InterstitialActivity extends AppCompatActivity
    

    in AndroidManifest.xml

        <activity
            android:name=".InterstitialActivity"
            ...
            android:screenOrientation="portrait"
            android:theme="@style/TranslucentTheme" />
    
    0 讨论(0)
  • 2020-12-02 05:34

    this happened after 27,use targetSdkVersion 26 replace, wait for google fixed it

    0 讨论(0)
  • 2020-12-02 05:35

    It is a conflict (bug) between Themes inside style.xml file in android versions 7 (Api levels 24,25) & 8 (api levels 26,27), when you have

    android:screenOrientation="portrait" :inside specific activity (that crashes) in AndroidManifest.xml

    &

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

    in the theme that applied to that activity inside style.xml

    It can be solve by these ways according to your need :

    1- Remove on of the above mentioned properties that make conflict

    2- Change Activity orientation to one of these values as you need : unspecified or behind and so on that can be found here : Google reference for android:screenOrientation `

    3- Set the orientation programmatically in run time

    0 讨论(0)
提交回复
热议问题