Previous MAUI-Behaviors MAUI-Device-APIs Next

.NET MAUI App Lifecycle

App lifecycle across platforms in .NET MAUI, since it’s slightly different depending on whether you’re running on Android, iOS, Windows, or macOS.

App Lifecycle in MAUI

1. Startup

Android → MainActivity.OnCreate() initializes the app, loads MauiProgram.CreateMauiApp().

iOS/macOS (Catalyst) → AppDelegate.FinishedLaunching() starts the app and loads the MAUI app.

Windows → WinUIApp.OnLaunched() initializes the app.

All platforms eventually call into MauiProgram.CreateMauiApp() which sets up services, resources, and the App class.

2. Running State

The app is active and visible.

Application.OnStart() is triggered when the app first runs.

Pages and Shell lifecycle events (OnAppearing, OnNavigated) occur during navigation.

3. Background / Sleep

Android → OnPause() is called when the app goes into the background.

iOS/macOS → OnResignActivation() or DidEnterBackground() is triggered.

Windows → OnSuspending() is called when the app is minimized or suspended.

In MAUI, this maps to Application.OnSleep().

4. Resume

Android → OnResume() when returning from background.

iOS/macOS → WillEnterForeground() or OnActivated().

Windows → OnResuming().

In MAUI, this maps to Application.OnResume().

5. Exit / Termination

Android → OnDestroy() when the activity is destroyed.

iOS/macOS → WillTerminate() when the app is killed.

Windows → OnSuspending() may be followed by termination.

In MAUI, this maps to Application.OnStop().

OnStart Running OnSleep OnResume OnStop Shell Init OnAppearing OnNavigating OnNavigated OnDisappearing

Summary Table

Lifecycle Stage Android iOS/macOS Windows MAUI Abstraction
Start OnCreate FinishedLaunching OnLaunched OnStart
Sleep OnPause DidEnterBackground OnSuspending OnSleep
Resume OnResume WillEnterForeground OnResuming OnResume
Exit OnDestroy WillTerminate Termination after suspend OnStop

Best Practices

  • Use OnStart, OnSleep, and OnResume in App.xaml.cs for cross-platform lifecycle handling.
  • Keep platform-specific logic in Handlers or platform-specific projects.
  • Avoid heavy work in lifecycle methods; offload to background services if possible.
  • Always save state in OnSleep to prevent data loss.

.NET MAUI App vs Shell Lifecycle

App Lifecycle (platform-level) and the Shell Lifecycle (navigation/UI-level) fit together in .NET MAUI:

App Lifecycle vs Shell Lifecycle

App Lifecycle (Platform-Level)

This is about the application process itself across Android, iOS/macOS, and Windows:

  • OnStart → App launches (MainActivity.OnCreate, AppDelegate.FinishedLaunching, WinUIApp.OnLaunched).
  • OnSleep → App goes into background (OnPause, DidEnterBackground, OnSuspending).
  • OnResume → App comes back to foreground (OnResume, WillEnterForeground, OnResuming).
  • OnStop / Terminate → App is closed (OnDestroy, WillTerminate, termination after suspend).

Shell Lifecycle (Navigation/UI-Level)

This is about the user interface and navigation container:

  • Shell Initialization → Routes registered, Shell object created.
  • OnAppearing → Shell or page becomes visible.
  • OnNavigating → Before navigation occurs (can cancel).
  • OnNavigated → After navigation completes.
  • OnDisappearing → Shell or page hidden or disposed.

Comparison Table

Stage App Lifecycle (Platform) Shell Lifecycle (UI)
Launch OnStart Shell constructor + route registration
Visible Running state OnAppearing (Shell/page)
Background OnSleep Page disappears (OnDisappearing)
Resume OnResume OnAppearing again
Navigation N/A (platform doesn’t handle this) OnNavigating / OnNavigated
Exit OnStop / Terminate Shell disposed

Key Insight

Think of it like two layers working together:

  • The App lifecycle is the outer shell controlled by the operating system (start, sleep, resume, exit).
  • The Shell lifecycle is the inner navigation flow controlled by MAUI’s Shell (appearing, navigating, disappearing).
Back to Index
Previous MAUI-Behaviors MAUI-Device-APIs Next
*