Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Crash when bringing app to foreground by tapping Android notification #33187

@carljohansen

Description

@carljohansen

Description

My app receives notifications via Firebase Cloud Messaging. Sometimes this happens when the app is in the background. I think that tapping the notification should bring the app to the foreground, and on iOS this is indeed what happens. But on Android, when I tap the notification I get a crash in my app:

12-17 10:19:32.880 E/AndroidRuntime(14585): android.runtime.JavaProxyThrowable: [System.ObjectDisposedException]: Cannot access a disposed object.
12-17 10:19:32.880 E/AndroidRuntime(14585): Object name: 'IServiceProvider'.
12-17 10:19:32.880 E/AndroidRuntime(14585): 	at Microsoft.Extensions.DependencyInjection.ServiceLookup.ThrowHelper.ThrowObjectDisposedException + 0x0(Unknown Source)
12-17 10:19:32.880 E/AndroidRuntime(14585): 	at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope.GetService + 0x8(Unknown Source)
12-17 10:19:32.880 E/AndroidRuntime(14585): 	at Microsoft.Maui.MauiContext+WrappedServiceProvider.GetService(/_/src/Core/src/MauiContext.cs:87)
12-17 10:19:32.880 E/AndroidRuntime(14585): 	at Microsoft.Maui.MauiContext+WrappedServiceProvider.GetService(/_/src/Core/src/MauiContext.cs:87)
12-17 10:19:32.880 E/AndroidRuntime(14585): 	at Microsoft.Maui.MauiContext+WrappedServiceProvider.GetService(/_/src/Core/src/MauiContext.cs:87)
12-17 10:19:32.880 E/AndroidRuntime(14585): 	at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetService + 0xb(Unknown Source)
12-17 10:19:32.880 E/AndroidRuntime(14585): 	at Microsoft.Maui.ElementHandlerExtensions.GetService(/_/src/Core/src/Handlers/ElementHandlerExtensions.cs:49)
12-17 10:19:32.880 E/AndroidRuntime(14585): 	at Microsoft.Maui.Controls.ContentPage.UpdateHideSoftInputOnTapped(/_/src/Controls/src/Core/ContentPage/ContentPage.Mapper.cs:40)
An unhandled exception of type 'Android.Runtime.JavaProxyThrowable' occurred in Mono.Android.Runtime.dll

12-17 10:19:32.880 E/AndroidRuntime(14585): 	at Microsoft.Maui.Controls.ContentPage.<.ctor>b__12_0(/_/src/Controls/src/Core/ContentPage/ContentPage.cs:61)
12-17 10:19:32.880 E/AndroidRuntime(14585): 	at Microsoft.Maui.Controls.Page.SendNavigatedTo(/_/src/Controls/src/Core/Page/Page.cs:774)
12-17 10:19:32.880 E/AndroidRuntime(14585): 	at Microsoft.Maui.Controls.Shell.SendNavigated(/_/src/Controls/src/Core/Shell/Shell.cs:1624)
12-17 10:19:32.880 E/AndroidRuntime(14585): 	at Microsoft.Maui.Controls.Shell.<.ctor>b__161_0(/_/src/Controls/src/Core/Shell/Shell.cs:1188)
12-17 10:19:32.880 E/AndroidRuntime(14585): 	at Microsoft.Maui.Controls.ShellNavigationManager+<>c__DisplayClass16_0.<HandleNavigated>g__FireNavigatedEvents|3(/_/src/Controls/src/Core/Shell/ShellNavigationManager.cs:274)
12-17 10:19:32.880 E/AndroidRuntime(14585): 	at Microsoft.Maui.Controls.ShellNavigationManager+<>c__DisplayClass16_0.<HandleNavigated>b__2(/_/src/Controls/src/Core/Shell/ShellNavigationManager.cs:264)
12-17 10:19:32.880 E/AndroidRuntime(14585): 	at Microsoft.Maui.Controls.BaseShellItem.OnAppearing(/_/src/Controls/src/Core/Shell/BaseShellItem.cs:172)
12-17 10:19:32.880 E/AndroidRuntime(14585): 	at Microsoft.Maui.Controls.ShellNavigationManager.HandleNavigated(/_/src/Controls/src/Core/Shell/ShellNavigationManager.cs:262)
12-17 10:19:32.880 E/AndroidRuntime(14585): 	at Microsoft.Maui.Controls.ShellNavigationManager+<>c__DisplayClass16_0.<HandleNavigated>g__WaitForWindowToSet|1(/_/src/Controls/src/Core/Shell/ShellNavigationManager.cs:243)
12-17 10:19:32.880 E/AndroidRuntime(14585): 	at Microsoft.Maui.Controls.Element.OnChildAdded(/_/src/Controls/src/Core/Element/Element.cs:632)
12-17 10:19:32.880 E/AndroidRuntime(14585): 	at Microsoft.Maui.Controls.ShellContent.OnChildAdded(/_/src/Controls/src/Core/Shell/ShellContent.cs:174)
12-17 10:19:32.880 E/AndroidRuntime(14585): 	at Microsoft.Maui.Controls.Element.AddLogicalChild(/_/src/Controls/src/Core/Element/Element.cs:225)
12-17 10:19:32.880 E/AndroidRuntime(14585): 	at Microsoft.Maui.Controls.ShellContent.set_ContentCache(/_/src/Controls/src/Core/Shell/ShellContent.cs:216)
12-17 10:19:32.880 E/AndroidRuntime(14585): 	at Microsoft.Maui.Controls.ShellContent.Microsoft.Maui.Controls.IShellContentController.GetOrCreateContent(/_/src/Controls/src/Core/Shell/ShellContent.cs:92)
12-17 10:19:32.880 E/AndroidRuntime(14585): 	at Microsoft.Maui.Controls.Platform.Compatibility.ShellSectionRenderer.OnCreateView(/_/src/Controls/src/Core/Compatibility/Handlers/Shell/Android/ShellSectionRenderer.cs:130)
12-17 10:19:32.880 E/AndroidRuntime(14585): 	at AndroidX.Fragment.App.Fragment.n_OnCreateView_Landroid_view_LayoutInflater_Landroid_view_ViewGroup_Landroid_os_Bundle_(C:\a\_work\1\s\generated\androidx.fragment.fragment\obj\Release

Steps to Reproduce

  1. Create an android app that receives FCM notifications.
  2. Run the app on android (I am using VS debug) and move it to the background (e.g. open Chrome).
  3. Send a message to your device.
  4. A notification appears in the normal android way.
  5. Tap the notification and get the crash shown above.

Link to public reproduction project repository

No response

Version with bug

10.0.20

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

Android 16, Maui .NET 10 SR2 (SR1 same problem)

Did you find any workaround?

No known workaround. I was hoping that SR2 would fix it (since it contains a fix for a disposed IServiceProvider problem), but I think that my particular issue is different (relating to UpdateHideSoftInputOnTapped).

Relevant log output

Metadata

Metadata

Assignees

No one assigned

    Labels

    s/needs-attentionIssue has more information and needs another lookt/bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions