BACK BUTTON VS NET 10

Giorgio Sfiligoi 571 Reputation points
2025-11-05T09:51:13.88+00:00

Platform: Android

With NET MAUI 9.0, pressing the 'hardware' Back Button generates the following events:

When the current page is MainPage:

OnSleep
Android – OnStop
Android – OnDestroy
shut down the app

When the current page is any other page: Go back to the previous page in the navigation stack

With NET MAUI 10, running the Emulator for API 35, the behavior is:

When the current page is MainPage: similar to above, but during shut down of the app, throws an unhandled exception ‘Android.Runtime.JavaProxyThrowable’ with InnerEception: “Cannot access a disposed object”

When the current page is any other page: Go back to the previous page in the navigation stack (same as NET 9)

With NET MAUI 10, running in a real cellular with API 36: the exception is thrown also when the current page in not MainPage.

I tried to add:

    protected override bool OnBackButtonPressed()
    {
        Debug.WriteLine("Back button pressed in ChildPage");
        return true;
    }

and also:

    public static MauiApp CreateMauiApp()
    {
        var builder = MauiApp.CreateBuilder();
        builder
            .UseMauiApp<App>()
#if ANDROID
            .ConfigureLifecycleEvents(events =>
            {
                events.AddAndroid(android => android.OnBackPressed((activity) =>
                {
                    Debug.WriteLine("Android - OnBackPressed");
                    return true;
                }));
            })
#endif
            .ConfigureFonts(fonts =>
            {
                fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
                fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
            });
#if DEBUG
		builder.Logging.AddDebug();
#endif
        return builder.Build();
    }

It happens that these events are detected when running in the Emulator, but they are completely ignored when running in the cellular phone.

Is this a bug in NET 10? Will it be fixed?

Developer technologies | .NET | .NET MAUI
{count} votes

Answer accepted by question author
  1. Jack Dang (WICLOUD CORPORATION) 5,205 Reputation points Microsoft External Staff Moderator
    2025-11-10T04:36:33.32+00:00

    Hello @Giorgio Sfiligoi ,

    Since the MAUI IServiceProvider (the .NET host) is already disposed when an Android fragment (ShellFragmentContainer.OnDestroy) attempts to resolve services.

    I have tested your provided project, and my assumption is that the most likely trigger is an early shutdown call (for example App.Current.Quit() in ChildPage.OnQuitClicked) or a lifecycle ordering change/bug in MAUI 10 where the host is disposed before fragments finish their OnDestroy work on some devices / API levels. The IServiceProvider can be found in output log following:

    enter image description here

    While this behavior not affecting your application, you can ignore it. If this concerns you, you can raise the github issue so that the MAUI team can look into it.


    I hope this clarifies!


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.