diff --git a/src/Maui/Prism.Maui/Navigation/PageNavigationService.cs b/src/Maui/Prism.Maui/Navigation/PageNavigationService.cs index 8c0c35378..daa5b91c7 100644 --- a/src/Maui/Prism.Maui/Navigation/PageNavigationService.cs +++ b/src/Maui/Prism.Maui/Navigation/PageNavigationService.cs @@ -4,6 +4,7 @@ using Prism.Events; using Prism.Extensions; using Prism.Mvvm; +using Prism.Navigation.Regions; using Application = Microsoft.Maui.Controls.Application; using XamlTab = Prism.Navigation.Xaml.TabbedPage; @@ -100,7 +101,9 @@ private async Task GoBackInternalAsync(INavigationParameters page = GetCurrentPage(); if (IsRoot(GetPageFromWindow(), page)) - throw new NavigationException(NavigationException.CannotPopApplicationMainPage, page); + { + return SendAppToBackground(page); + } parameters.GetNavigationParametersInternal().Add(KnownInternalParameters.NavigationMode, NavigationMode.Back); @@ -1255,6 +1258,18 @@ internal static bool UseReverseNavigation(Page currentPage, Type nextPageType) return MvvmHelpers.HasNavigationPageParent(currentPage) && MvvmHelpers.IsSameOrSubclassOf(nextPageType); } + private INavigationResult SendAppToBackground(Page page) + { +#if ANDROID + MauiAppCompatActivity activity = Window.Handler.PlatformView as MauiAppCompatActivity; + activity.MoveTaskToBack(true); + + return new NavigationResult(); +#else + throw new NavigationException(NavigationException.CannotPopApplicationMainPage, page); +#endif + } + private INavigationResult Notify(NavigationRequestType type, INavigationParameters parameters, Exception exception = null) { var result = new NavigationResult(exception);