Skip to content

Commit

Permalink
send android app to background when navigating back on the root page
Browse files Browse the repository at this point in the history
  • Loading branch information
brianlagunas committed Jul 4, 2024
1 parent fbee726 commit 69a1177
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/Maui/Prism.Maui/Navigation/PageNavigationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -100,7 +101,9 @@ private async Task<INavigationResult> GoBackInternalAsync(INavigationParameters

page = GetCurrentPage();
if (IsRoot(GetPageFromWindow(), page))
throw new NavigationException(NavigationException.CannotPopApplicationMainPage, page);
{
return SendAppToBackground(page);
}

parameters.GetNavigationParametersInternal().Add(KnownInternalParameters.NavigationMode, NavigationMode.Back);

Expand Down Expand Up @@ -1255,6 +1258,18 @@ internal static bool UseReverseNavigation(Page currentPage, Type nextPageType)
return MvvmHelpers.HasNavigationPageParent(currentPage) && MvvmHelpers.IsSameOrSubclassOf<ContentPage>(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);
Expand Down

0 comments on commit 69a1177

Please sign in to comment.