In MAUI it will re-open my APP when I quit and open another app

mc 5,041 Reputation points
2025-01-09T10:00:45.93+00:00

in MAUI Platform IOS:

I open my app and open Page1 and then tab the screen to open another APP

and then quit that APP then return to my APP the Page1 is disappeared and it is the home page.

does it closed and re-open?

how to keep the Page1(or other pages) when I open another app in my mobile?

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,807 questions
{count} votes

2 answers

Sort by: Most helpful
  1. ASFEND YAR HAMID 156 Reputation points MVP
    2025-01-12T08:07:22.1933333+00:00

    This issue occurs because iOS has strict memory management policies. If your app is moved to the background and iOS needs to free up resources, it may terminate your app. When you return, the app is relaunched, and by default, it starts from the initial page (home page) as the navigation stack is not preserved.

    To keep the state of Page1 (or other pages) and maintain the navigation stack when returning to your app, you need to implement state persistence in your .NET MAUI app.

    0 comments No comments

  2. ASFEND YAR HAMID 156 Reputation points MVP
    2025-01-12T08:14:39.76+00:00

    iOS may close your app when it goes to the background due to system memory management. When you return, the app restarts at the home page.

    To keep Page1 when switching apps:

    1. Save the current page when the app goes to the background:
         protected override void OnSleep() { var state = Shell.Current.GetNavigationState(); Preferences.Set("AppState", state); }
         
         
      
    2. Restore the page when the app restarts:
         protected override void OnStart() { if (Preferences.ContainsKey("AppState")) { var state = Preferences.Get("AppState", string.Empty); Shell.Current.SetNavigationState(state); } }
         
         
      

    This ensures the user returns to the last page they were on.

    0 comments No comments

Your answer

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