Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

App Crash (Android) androidx.fragment.app.FragmentManager.checkStateLoss #19776

Closed
pulmuone opened this issue Jan 9, 2024 · 4 comments
Closed
Labels
platform/android 🤖 t/bug Something isn't working

Comments

@pulmuone
Copy link

pulmuone commented Jan 9, 2024

Description

App Crash (Android)
androidx.fragment.app.FragmentManager.checkStateLoss
Java.Lang.IllegalStateException: Can not perform this action after onSaveInstanceState

Steps to Reproduce

No response

Link to public reproduction project repository

No response

Version with bug

8.0.3

Is this a regression from previous behavior?

Yes, this used to work in .NET MAUI

Last version that worked well

8.0.3

Affected platforms

Android

Affected platform versions

Android 9, Android 10, Android 11

Did you find any workaround?

No response

Relevant log output

Xamarin Exception Stack:
Java.Lang.IllegalStateException: Can not perform this action after onSaveInstanceState
  at Java.Interop.JniEnvironment.InstanceMethods.CallIntMethod(JniObjectReference instance, JniMethodInfo method, JniArgumentValue* args)
  at Java.Interop.JniPeerMembers.JniInstanceMethods.InvokeAbstractInt32Method(String encodedMember, IJavaPeerable self, JniArgumentValue* parameters)
  at AndroidX.Fragment.App.BackStackRecord.Commit()
  at Microsoft.Maui.Platform.NavigationRootManager.SetContentView(IView view)
  at Microsoft.Maui.Platform.NavigationRootManager.Disconnect()
  at Microsoft.Maui.Handlers.WindowHandler.DisconnectHandler(NavigationRootManager navigationRootManager)
  at Microsoft.Maui.Handlers.WindowHandler.OnDisconnectHandler(Object platformView)
  at Microsoft.Maui.Handlers.ElementHandler.DisconnectHandler(Object platformView)
  at Microsoft.Maui.Handlers.ElementHandler.Microsoft.Maui.IElementHandler.DisconnectHandler()
  at Microsoft.Maui.Controls.Element.SetHandler(IElementHandler newHandler)
  at Microsoft.Maui.Controls.Element.set_Handler(IElementHandler value)
  at Microsoft.Maui.Platform.ElementExtensions.SetHandler(Context nativeElement, IElement element, IMauiContext context)
  at Microsoft.Maui.Platform.ElementExtensions.SetWindowHandler(Activity platformWindow, IWindow window, IMauiContext context)
  at Microsoft.Maui.Platform.ApplicationExtensions.CreatePlatformWindow(Activity activity, IApplication application, Bundle savedInstanceState)
  at Microsoft.Maui.MauiAppCompatActivity.OnCreate(Bundle savedInstanceState)
  at EMP.PDA.MainActivity.OnCreate(Bundle savedInstanceState)
  at Android.App.Activity.n_OnCreate_Landroid_os_Bundle_(IntPtr jnienv, IntPtr native__this, IntPtr native_savedInstanceState)
  at Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PPL_V(_JniMarshal_PPL_V callback, IntPtr jnienv, IntPtr klazz, IntPtr p0)
  at java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState
  at androidx.fragment.app.FragmentManager.checkStateLoss(FragmentManager.java:1632)
  at androidx.fragment.app.FragmentManager.enqueueAction(FragmentManager.java:1672)
  at androidx.fragment.app.BackStackRecord.commitInternal(BackStackRecord.java:341)
  at androidx.fragment.app.BackStackRecord.commit(BackStackRecord.java:306)
  at crc643e9f0f68c1688c10.MainActivity.n_onCreate(Native Method)
  at crc643e9f0f68c1688c10.MainActivity.onCreate(MainActivity.java:45)
  at android.app.Activity.performCreate(Activity.java:7994)
  at android.app.Activity.performCreate(Activity.java:7978)
  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1548)
  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3406)
  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3607)
  at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
  at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
  at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2068)
  at android.os.Handler.dispatchMessage(Handler.java:106)
  at android.os.Looper.loop(Looper.java:223)
  at android.app.ActivityThread.main(ActivityThread.java:7680)
  at java.lang.reflect.Method.invokeNative(Native Method)
  at java.lang.reflect.Method.invoke(Method.java:423)
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)

Thread 2:
0   dalvik.system.VMStack.getThreadStackTrace(VMStack.java:-2)
1   java.lang.Thread.getStackTrace(Thread.java:1736)
2   java.lang.Thread.getAllStackTraces(Thread.java:1812)
3   com.microsoft.appcenter.crashes.Crashes.saveUncaughtException(Crashes.java:1157)
4   com.microsoft.appcenter.crashes.WrapperSdkExceptionManager.saveWrapperException(WrapperSdkExceptionManager.java:58)
5   crc643e9f0f68c1688c10.MainActivity.n_onCreate(MainActivity.java:-2)
6   crc643e9f0f68c1688c10.MainActivity.onCreate(MainActivity.java:45)
7   android.app.Activity.performCreate(Activity.java:7994)
8   android.app.Activity.performCreate(Activity.java:7978)
9   android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1548)
10  android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3406)
11  android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3607)
12  android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
13  android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
14  android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
15  android.app.ActivityThread$H.handleMessage(ActivityThread.java:2068)
16  android.os.Handler.dispatchMessage(Handler.java:106)
17  android.os.Looper.loop(Looper.java:223)
18  android.app.ActivityThread.main(ActivityThread.java:7680)
19  java.lang.reflect.Method.invokeNative(Method.java:-2)
20  java.lang.reflect.Method.invoke(Method.java:423)
21  com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
22  com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
@pulmuone pulmuone added the t/bug Something isn't working label Jan 9, 2024
@PureWeen
Copy link
Member

PureWeen commented Jan 9, 2024

Duplicate of #11501

@PureWeen PureWeen marked this as a duplicate of #11501 Jan 9, 2024
@PureWeen PureWeen closed this as completed Jan 9, 2024
@pulmuone
Copy link
Author

pulmuone commented Jan 9, 2024

Duplicate of #11501

<AndroidLinkResources>false</AndroidLinkResources>
Will this error be resolved by adding this in the release?

@pulmuone
Copy link
Author

Even in the latest version of Maui, crashes occur several times a day.

@pulmuone
Copy link
Author

pulmuone commented Feb 1, 2024

I found the cause in Android.
https://android.googlesource.com/platform/frameworks/base/+/refs/heads/master/core/java/android/app/FragmentManager.java

Error Message : "Can not perform this action after onSaveInstanceState"

private void checkStateLoss() {
    if (mStateSaved) {
        throw new IllegalStateException(
                "Can not perform this action after onSaveInstanceState");
    }
    if (mNoTransactionsBecause != null) {
        throw new IllegalStateException(
                "Can not perform this action inside of " + mNoTransactionsBecause);
    }
}

@github-actions github-actions bot locked and limited conversation to collaborators Mar 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
platform/android 🤖 t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants