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

MAUI Android MainPage assignments break (or crash) the app if it's backgrounded or OnResume #18921

Closed
dinisvieira opened this issue Nov 21, 2023 · 1 comment
Labels
migration-compatibility Xamarin.Forms to .NET MAUI Migration, Upgrade Assistant, Try-Convert platform/android 🤖 t/bug Something isn't working

Comments

@dinisvieira
Copy link

Description

Doing an Android MainPage assignment when the app is backgrounded or during App.xaml.cs OnResume breaks or crashes the app.
The app can either crash immediately or in some other situations the Assignment doesn't happen but it's not longer possible to do any other MainPage assignment afterwards.

Steps to Reproduce

Steps to Try:

  • Clone and Build Repro project
  • Open App
  • Click buttons to do Navigations/MainPage assignments (optional)
  • Press Home button to put the app in background
  • Open app again
    • Notice that app Crashed OR app didn't Navigate to the "background page"
  • Click buttons to do Navigations/MainPage assignments (optional)
    • Notice Navigations don't work anymore

Link to public reproduction project repository

https://github.com/dinisvieira/maui-nav-on-background/tree/main

Version with bug

8.0.3

Is this a regression from previous behavior?

Yes, this used to work in Xamarin.Forms

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

Android 11, 13 and possibly all other versions.

Did you find any workaround?

Not doing any MainPage assignments when the app is in Background or Resuming.

Relevant log output

[ERROR] FATAL UNHANDLED EXCEPTION: Java.Lang.IllegalStateException: Can not perform this action after onSaveInstanceState
   at Java.Interop.JniEnvironment.InstanceMethods.CallIntMethod(JniObjectReference instance, JniMethodInfo method, JniArgumentValue* args) in /Users/runner/work/1/s/xamarin-android/external/Java.Interop/src/Java.Interop/obj/Release/net7.0/JniEnvironment.g.cs:line 20203
   at Java.Interop.JniPeerMembers.JniInstanceMethods.InvokeAbstractInt32Method(String encodedMember, IJavaPeerable self, JniArgumentValue* parameters) in /Users/runner/work/1/s/xamarin-android/external/Java.Interop/src/Java.Interop/Java.Interop/JniPeerMembers.JniInstanceMethods_Invoke.cs:line 492
   at AndroidX.Fragment.App.BackStackRecord.Commit() in C:\a\_work\1\s\generated\androidx.fragment.fragment\obj\Release
et6.0-android\generated\src\AndroidX.Fragment.App.BackStackRecord.cs:line 131
   at Microsoft.Maui.Platform.NavigationRootManager.SetContentView(IView view) in D:\a\_work\1\s\src\Core\src\Platform\Android\Navigation\NavigationRootManager.cs:line 146
   at Microsoft.Maui.Platform.NavigationRootManager.Connect(IView view, IMauiContext mauiContext) in D:\a\_work\1\s\src\Core\src\Platform\Android\Navigation\NavigationRootManager.cs:line 87
   at Microsoft.Maui.Handlers.WindowHandler.CreateRootViewFromContent(IWindowHandler handler, IWindow window) in D:\a\_work\1\s\src\Core\src\Handlers\Window\WindowHandler.Android.cs:line 91
   at Microsoft.Maui.Handlers.WindowHandler.MapContent(IWindowHandler handler, IWindow window) in D:\a\_work\1\s\src\Core\src\Handlers\Window\WindowHandler.Android.cs:line 27
   at Microsoft.Maui.PropertyMapper`2.<>c__DisplayClass5_0[[Microsoft.Maui.IWindow, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[Microsoft.Maui.Handlers.IWindowHandler, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].<Add>b__0(IElementHandler h, IElement v) in D:\a\_work\1\s\src\Core\src\PropertyMapper.cs:line 172
   at Microsoft.Maui.PropertyMapper.UpdatePropertyCore(String key, IElementHandler viewHandler, IElement virtualView) in D:\a\_work\1\s\src\Core\src\PropertyMapper.cs:line 47
   at Microsoft.Maui.PropertyMapper.UpdateProperty(IElementHandler viewHandler, IElement virtualView, String property) in D:\a\_work\1\s\src\Core\src\PropertyMapper.cs:line 72
   at Microsoft.Maui.Handlers.ElementHandler.UpdateValue(String property) in D:\a\_work\1\s\src\Core\src\Handlers\Element\ElementHandler.cs:line 87
   at Microsoft.Maui.Controls.Window.OnPropertyChanged(String propertyName) in D:\a\_work\1\s\src\Controls\src\Core\Window\Window.cs:line 296
   at Microsoft.Maui.Controls.BindableObject.SetValueActual(BindableProperty property, BindablePropertyContext context, Object value, Boolean currentlyApplying, SetValueFlags attributes, SetterSpecificity specificity, Boolean silent) in D:\a\_work\1\s\src\Controls\src\Core\BindableObject.cs:line 631
   at Microsoft.Maui.Controls.BindableObject.SetValueCore(BindableProperty property, Object value, SetValueFlags attributes, SetValuePrivateFlags privateAttributes, SetterSpecificity specificity) in D:\a\_work\1\s\src\Controls\src\Core\BindableObject.cs:line 559
   at Microsoft.Maui.Controls.BindableObject.SetValue(BindableProperty property, Object value) in D:\a\_work\1\s\src\Controls\src\Core\BindableObject.cs:line 464
   at Microsoft.Maui.Controls.Window.set_Page(Page value) in D:\a\_work\1\s\src\Controls\src\Core\Window\Window.cs:line 122
   at Microsoft.Maui.Controls.Application.set_MainPage(Page value) in D:\a\_work\1\s\src\Controls\src\Core\Application\Application.cs:line 106
   at MauiAppMainPageAssignments.App.NavigateBackground() in C:\Users\dinis\Source\Repos\MauiAppMainPageAssignments\MauiAppMainPageAssignments\App.xaml.cs:line 24
   at MauiAppMainPageAssignments.App.OnResume() in C:\Users\dinis\Source\Repos\MauiAppMainPageAssignments\MauiAppMainPageAssignments\App.xaml.cs:line 30
   at Microsoft.Maui.Controls.Application.SendResume() in D:\a\_work\1\s\src\Controls\src\Core\Application\Application.cs:line 354
   at Microsoft.Maui.Controls.Window.Microsoft.Maui.IWindow.Resumed() in D:\a\_work\1\s\src\Controls\src\Core\Window\Window.cs:line 549
   at Microsoft.Maui.LifecycleEvents.AppHostBuilderExtensions.<>c.<OnConfigureLifeCycle>b__2_1(Activity activity) in D:\a\_work\1\s\src\Core\src\Hosting\LifecycleEvents\AppHostBuilderExtensions.Android.cs:line 28
   at Microsoft.Maui.MauiAppCompatActivity.<OnRestart>b__10_0(OnRestart del) in D:\a\_work\1\s\src\Core\src\Platform\Android\MauiAppCompatActivity.Lifecycle.cs:line 75
   at Microsoft.Maui.LifecycleEvents.LifecycleEventServiceExtensions.InvokeLifecycleEvents[OnRestart](IServiceProvider services, Action`1 action) in D:\a\_work\1\s\src\Core\src\LifecycleEvents\LifecycleEventServiceExtensions.cs:line 31
   at Microsoft.Maui.MauiAppCompatActivity.OnRestart() in D:\a\_work\1\s\src\Core\src\Platform\Android\MauiAppCompatActivity.Lifecycle.cs:line 75
   at Android.App.Activity.n_OnRestart(IntPtr jnienv, IntPtr native__this) in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/obj/Release/net8.0/android-34/mcw/Android.App.Activity.cs:line 4907
   at Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PP_V(_JniMarshal_PP_V callback, IntPtr jnienv, IntPtr klazz) in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.Runtime/JNINativeWrapper.g.cs:line 26
  --- End of managed Java.Lang.IllegalStateException stack trace ---
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 crc6488302ad6e9e4df1a.MauiAppCompatActivity.n_onRestart(Native Method)
	at crc6488302ad6e9e4df1a.MauiAppCompatActivity.onRestart(MauiAppCompatActivity.java:113)
	at android.app.Instrumentation.callActivityOnRestart(Instrumentation.java:1553)
	at android.app.Activity.performRestart(Activity.java:8766)
	at android.app.ActivityThread.performRestartActivity(ActivityThread.java:5940)
	at android.app.servertransaction.TransactionExecutor.performLifecycleSequence(TransactionExecutor.java:244)
	at android.app.servertransaction.TransactionExecutor.cycleToPath(TransactionExecutor.java:201)
	at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:173)
	at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97)
	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2584)
	at android.os.Handler.dispatchMessage(Handler.java:106)
	at android.os.Looper.loopOnce(Looper.java:226)
	at android.os.Looper.loop(Looper.java:313)
	at android.app.ActivityThread.main(ActivityThread.java:8810)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:604)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1067)
@dinisvieira dinisvieira added the t/bug Something isn't working label Nov 21, 2023
@jfversluis
Copy link
Member

Duplicate of #11501

@jfversluis jfversluis marked this as a duplicate of #11501 Nov 21, 2023
@jfversluis jfversluis closed this as not planned Won't fix, can't repro, duplicate, stale Nov 21, 2023
@samhouts samhouts added the migration-compatibility Xamarin.Forms to .NET MAUI Migration, Upgrade Assistant, Try-Convert label Dec 12, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Jan 12, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
migration-compatibility Xamarin.Forms to .NET MAUI Migration, Upgrade Assistant, Try-Convert platform/android 🤖 t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants