react-native: App crashes when coming back from another activity with landscape orientation On Android 8.1

Environment

[skip envinfo]

Description

I have a Reat Native v0.44 Main Activity A which is configured as portrait orientation while destination Activity B is landscape, when A startActivityForResult to B and B finished ok with result to pass to A, the App crashed.

If using following code to set orientation in B, the problem could be solved temporarily:

              boolean isOverAndroid8 = Build.VERSION.SDK_INT > Build.VERSION_CODES.N;
		if (isOverAndroid8) {
			setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
		} else {
			setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
		}

below is styles.xml:

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>

    <style name="AppTheme.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
    </style>

    <style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar"/>

    <style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light"/>

</resources>

So, i think it has something related between Reat Native and Android 8.1.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 3
  • Comments: 39 (3 by maintainers)

Most upvoted comments

Hi friends, after a long time I managed to fix this error. You need to add android: launchMode = “singleTask” in AndroidManifest.xml

what would it be like this

<activity android:name=“.MainActivity” android:label=“@string/app_name” android:configChanges=“keyboard|keyboardHidden|orientation|screenSize” android:windowSoftInputMode=“adjustPan” android:launchMode=“singleTask” // ++++++++++++++

I had a problem due to react-native-splash-screen library

still happening on 0.60.5

Привет друзья, спустя долгое время мне удалось исправить данную ошибку. Необходимо в AndroidManifest.xml добавить android:launchMode=“singleTask”

что бы было вот так

<activity android:name=“.MainActivity” android:label=“@string/app_name” android:configChanges=“keyboard|keyboardHidden|orientation|screenSize” android:windowSoftInputMode=“adjustPan” android:launchMode=“singleTask” // ++++++++++++++ >

у меня была проблема из за библиотеки react-native-splash-screen

I have the same problem ,my react native version is 0.56.0 , but my all activity is setted android:screenOrientation=“portrait” , so I guess it has something related between React Native and Android 8.1,maybe the orientation has no effect,the crash information is: Fatal Exception: java.lang.AssertionError: Pausing an activity that is not the current activity, this is incorrect! Current activity: MainActivity Paused activity: MainActivity at com.facebook.infer.annotation.Assertions.assertCondition(Assertions.java:72) at com.facebook.react.ReactInstanceManager.onHostPause(ReactInstanceManager.java:500) at com.facebook.react.ReactActivityDelegate.onPause(ReactActivityDelegate.java:99) at com.facebook.react.ReactActivity.onPause(ReactActivity.java:58) at android.app.Activity.performPause(Activity.java:7422) at android.app.Instrumentation.callActivityOnPause(Instrumentation.java:1409) at android.app.ActivityThread.performPauseActivityIfNeeded(ActivityThread.java:4176) at android.app.ActivityThread.performPauseActivity(ActivityThread.java:4153) at android.app.ActivityThread.performPauseActivity(ActivityThread.java:4122) at android.app.ActivityThread.handlePauseActivity(ActivityThread.java:4096) at android.app.ActivityThread.-wrap15(Unknown Source) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1779) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:198) at android.app.ActivityThread.main(ActivityThread.java:7015) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:521) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:837)

Finally, we mitigated the problem by extending ReactFragment and override onPause function. We did a try-catch for calling super.onPause: try { super.onPause() } catch (assertError: AssertionError) { // report error to somewhere }

Because all crashes happened to activities that will be destroyed, we do not care if there are lifecycle issues with the try-catch. We did not observe any other RN life cycle related crashes or complains with this fix.

I have the same problem

"react-native": "0.62.2"
android:launchMode="singleTask"

Probably related to the use react-native-splash-screen Android Sdk 28 Android System Version 8.0.0

The same here, just deployed updated app with 0.61.5 react native and facing the same issue across multiple users: java.lang.AssertionError: Pausing an activity that is not the current activity, this is incorrect! Current activity: MainActivity Paused activity: MainActivity at com.facebook.infer.annotation.Assertions.assertCondition(Assertions.java:72) at com.facebook.react.ReactInstanceManager.onHostPause(ReactInstanceManager.java:512) at com.facebook.react.ReactActivityDelegate.onPause(ReactActivityDelegate.java:99) at com.facebook.react.ReactActivity.onPause(ReactActivity.java:58) at android.app.Activity.performPause(Activity.java:8168) at android.app.Instrumentation.callActivityOnPause(Instrumentation.java:1508) at android.app.ActivityThread.performPauseActivityIfNeeded(ActivityThread.java:4725) at android.app.ActivityThread.performPauseActivity(ActivityThread.java:4686) at android.app.ActivityThread.handlePauseActivity(ActivityThread.java:4638) at android.app.servertransaction.PauseActivityItem.execute(PauseActivityItem.java:46) at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:176) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2146) at android.os.Handler.dispatchMessage(Handler.java:107) at android.os.Looper.loop(Looper.java:237) at android.app.ActivityThread.main(ActivityThread.java:7762) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1047)

@truongluong1314520 no, till now, still using above code to fix the orientation.