background

On the morning of July 18, 2018, The Telecommunications Terminal Industry Association (TAF) issued the Self-regulatory Convention on High API Level Prepositioning and Distribution of Mobile Application Software (hereinafter referred to as the Convention). OPPO, Huawei, Baidu, 360, Alibaba, Xiaomi, VIVO and Tencent, as the initiators, signed the Convention and issued a joint initiative: calling on the majority of mobile application software prepositioning and distribution service providers, refusing to put applications with low API level on the shelf and updating them in time, and jointly safeguarding users’ rights and interests. As of May 1, 2019, new and pre-installed apps should be developed based on Android 8.0 (API level 26) or above, according to the CONVENTION. As of August 1, 2019, updates to existing apps should be based on Android 8.0 (API level 26) and above.

The old project started to make a higher version adaptation, this does not change the targetSDK version to the latest 28, the problem is constantly, here specially to make a note

Abnormal log

Caused by: java.lang.IllegalStateException: Only fullscreen opaque activities can request orientation
                                                     at android.app.Activity.onCreate(Activity.java:1081)
                                                     at android.support.v4.app.BaseFragmentActivityDonut.onCreate(BaseFragmentActivityDonut.java:39)
                                                     at android.support.v4.app.FragmentActivity.onCreate(FragmentActivity.java:278)
                                                     at com.seeyon.mobile.android.model.gesture.activity.BaseGuestureActivity.onCreate(BaseGuestureActivity.java:31)
                                                     at com.seeyon.mobile.android.model.base.BaseActivity.onCreate(BaseActivity.java:83)
                                                     at com.seeyon.mobile.android.model.base.ActionBarBaseActivity.onCreate(ActionBarBaseActivity.java:61)
                                                     at com.seeyon.mobile.android.model.flow.FlowSearchActivity.onCreate(FlowSearchActivity.java:53)
                                                     at android.app.Activity.performCreate(Activity.java:7372)
                                                     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1218)
                                                     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3147)
                                                     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3302) 
                                                     at android.app.ActivityThread.-wrap12(Unknown Source:0) 
                                                     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1891) 
                                                     at android.os.Handler.dispatchMessage(Handler.java:108) 
                                                     at android.os.Looper.loop(Looper.java:166) 
                                                     at android.app.ActivityThread.main(ActivityThread.java:7425) 
                                                     at java.lang.reflect.Method.invoke(Native Method) 
Copy the code

First of all, this is a Google bug, don’t wait to fix it, it is still in 9.0.

The source code

//Need to pay attention mActivityInfo.isFixedOrientation() and ActivityInfo.isTranslucentOrFloating(ta)
    if (getApplicationInfo().targetSdkVersion >= O_MR1 && mActivityInfo.isFixedOrientation()) {
        final TypedArray ta = obtainStyledAttributes(com.android.internal.R.styleable.Window);
        final boolean isTranslucentOrFloating = ActivityInfo.isTranslucentOrFloating(ta);
        ta.recycle();

        //Exception occurred
        if (isTranslucentOrFloating) {
            throw new IllegalStateException(
                    "Only fullscreen opaque activities can request orientation"); }}Copy the code

Floating activities can’t be fixed orientation

* Returns true if the activity's orientation is fixed. * @hide */ public boolean isFixedOrientation() { return isFixedOrientationLandscape() || isFixedOrientationPortrait() || screenOrientation == SCREEN_ORIENTATION_LOCKED; } /** * Returns true if the activity's orientation is fixed to portrait. * @hide */ boolean isFixedOrientationPortrait()  { return isFixedOrientationPortrait(screenOrientation); } /** * Returns true if the activity's orientation is fixed to portrait. * @hide */ public static boolean isFixedOrientationPortrait(@ScreenOrientation int orientation) { return orientation == SCREEN_ORIENTATION_PORTRAIT || orientation == SCREEN_ORIENTATION_SENSOR_PORTRAIT || orientation == SCREEN_ORIENTATION_REVERSE_PORTRAIT || orientation == SCREEN_ORIENTATION_USER_PORTRAIT; } /** * Determines whether the {@link Activity} is considered translucent or floating. * @hide */ public static boolean isTranslucentOrFloating(TypedArray attributes) { final boolean isTranslucent = attributes.getBoolean(com.android.internal.R.styleable.Window_windowIsTranslucent, false); final boolean isSwipeToDismiss = ! attributes.hasValue(com.android.internal.R.styleable.Window_windowIsTranslucent) && attributes.getBoolean(com.android.internal.R.styleable.Window_windowSwipeToDismiss, false); final boolean isFloating = attributes.getBoolean(com.android.internal.R.styleable.Window_windowIsFloating, false); return isFloating || isTranslucent || isSwipeToDismiss; }Copy the code

You can see from the source code above, the solution to the problem

The solution

  • Unfixed direction

Such as removal of android: screenOrientation = “portrait”, or don’t call set the direction of the code

  • IsTranslucentOrFloating returns false

    Only the android: windowIsTranslucent

<item name="android:windowIsTranslucent">false</item>
Copy the code
If there's also windowising at the same timeCopy the code
<item name="android:windowIsTranslucent">false</item>
<item name="android:windowIsFloating">false</item>
Copy the code

Conclusion:

The purpose of this change is to prevent non-full-screen activities from locking the screen rotation, since the current Activity is transparent, floating, or swiping to cancel. Locking should be determined by the full-screen Activity, not by the Activity that does not fully occupy the screen.