[Android] 8.0 Only fullscreen opaque activities can request orientation 에러

문제 인식

회사에서 MVP로 화면 잠금 어플리케이션을 만들고 있다. Activity onCreate()시에 에러가 발생했다. 에러로그는 다음과 같다.

Only fullscreen opaque activities can request orientation

문제 해결방안

이 문제는 Android 8.0 으로 업데이트 시 발생한다.

해결방법

<style name="Theme.Transparent" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="android:windowIsTranslucent">true</item>
</style>

화면 스타일 중 windowsIsTranslucent가 true일 때

<activity
    android:name=".LockscreenActivity"
    android:excludeFromRecents="true"
    android:launchMode="singleTop"
    android:screenOrientation="portrait"
    android:theme="@style/Theme.Transparent"
    android:windowSoftInputMode="stateHidden|adjustResize" />

화면 방향을 강제 지정하면 오류가 발생하는데 screenOrientation을 unspecified 로 변경하면 오류가 사라진다.

android:screenOrientation="unspecified"

결과

  • 에러가 발생하지 않는다.