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?