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

you should not lock orientation of your activities
stackoverflow android only fullscreen opaque activities can request orientation
android application screen orientation
screen orientation android
android set screen orientation portrait programmatically
transparent activity android
change orientation of android app
transparent activity in android programmatically

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.

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.

java.lang.IllegalStateException: Only fullscreen opaque activities , I also faced the same problem. As others said, If I deleted android:​screenOrientation=”portrait” or overrided it with  There are few reasons why you may want to lock your screen orientation when developing android application. For instance, menu or intro activity pages are sometimes fix to a particular screen orientation. Another important example is in games. Since landscape mode afford more space in most android device, game play screen is always fix to

The workaround is to set targetSdk back to 26.

The reason why is your application crashes is here in this commit.

As you can see here, you are not the only one - this behavior has been reported to Google as issue. It has been fixed, but we don't know how and when it will be released.

I can also confirm what "sofakingforever" says in comments, if there is non-translucent activity with fixed orientation behind your translucent, the translucent will not rotate. So you can just remove android:screenOrientation="portrait" from manifest as well.

Activity, Even if you remove android:screenOrientation="portrait" from the floating or Last chance if the previous tips do not work : target SDK 26 instead o 27. your translucent activity will have the same orientation lock: portrait. orientation lock in android programmatically. Locks the screen (activity) in whatever the orientation it was. edited Feb 27 '16 at 23:02.

The solution worked for me is deleting


from all the full screen transparent activities which means their theme contains

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

Also to make sure that orientation works correct for below Oreo I added this to the onCreate() of the activities.

protected void onCreate(Bundle savedInstanceState) {
    // This activity is a fullscreen transparent activity, so after Oreo Android doesn't allow fullscreen
    // transparent activities to specify android:screenOrientation="portrait" in the manifest. It will pick up
    // from the background activity. But for below Oreo we should make sure that requested orientation is portrait.

Don't use windowIsTranslucent together with screenOrientation , During this time the user can see the activity on-screen, though it may not be in the will change slightly between applications targeting platforms starting with Build. a configuration change (such as a change in screen orientation, language, of the lock screen whenever the lockscreen is up and this activity has another  The lock() property of the ScreenOrientation interface locks the orientation of the containing document to its default orientation. Syntax ScreenOrientation.lock(orientation) Parameters orientation An orientation lock type. One of the following: "any" "natural" "landscape" "portrait" "portrait-primary" "portrait-secondary" "landscape-primary

I solved this issues by changing this line in NoActionBar styles

In target version 27 only i got this issue and i solved by using below line

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

java.lang.IllegalStateException: Only fullscreen activities can , IllegalStateException: Only fullscreen opaque activities can request orientation. What a crap. device yet. The joke is that this problem does not seem to occur in Android 9 Pie. They have given a demo API URL to load an image in recycler view. I have to After meeting I have locked myself in the room & cried for 2hrs. Is there a way to lock orientation during runtime? For example I'd like to allow the user to lock the screen to landscape if the user currently in landscape and toggle the menu option. android orientation

So what I did was remove any screenOrientation property from manifest and add it to my BaseActivity (from which all my activities extend), this code

 if(!(this instanceof TranslucentActivity)){

The TranslucentActivity will have the orientation from the Activity behind.

[TIMOB-26157] Android: A semi-transparent or modal Window with a , Got this error when targeting Android O (API 27). java.lang. It's quite disappointing that a bug that crashes apps is not fixed faster. using doesn't support locking the orientation on translucent activities anymore on compileSdkVersion 27 . We see that the crash has only happened on one device so far. So, if the lock is set for only one orientation, the screen orientation will never change until the screen orientation is unlocked. Otherwise, the screen orientation will change from an orientation to another as long as the orientations are amongst the orientations the device has been locked to.

Making app ready for Oreo - UC Engineering, An app targeting API Level 26 (aka: Android 8.0) or higher will crash with an Note that the app crashes (or hangs) on startup and fails to display the window. you can no longer assign an orientation to a "translucent" activity window. Setting the modal and opacity properties causes Titanium to use a  In Android 8.1 (API level 27) and lower, accessibility services cannot always determine when a specific pane of the screen was updated, such as when an activity replaces one fragment with another fragment. Panes consist of logically-grouped, visually-related UI elements that typically comprise a fragment.

Some of the critical changes which affectsapps that target Android 8.0+ are: Android https://issuetracker.google.com/issues/67920140; Screen orientation request issue -https://stackoverflow.com/questions/46980697/lock-screen-​orientation-when-targeting-android-api-27-with-a-non-opaque-activity. 1. Lock screen orientation. 2. Prevent Activity to recreated. 3. Save basic state. 4. Save complex objects. Lock screen orientation. To lock the screen orientation change of any screen (activity) of your android application makes your activity display only in one mode i.e. either Landscape or Portrait. This is the simplest way to handle screen

"orientation" The screen orientation has changed — the user has rotated the device. Note: If your application targets Android 3.2 (API level 13) or higher, then you should also declare the "screenSize" and "screenLayout" configurations, because they might also change when a device switches between portrait and landscape orientations.