.NET MAUI › App Lifecycle & Windows

How do you persist and restore app state across launches?

Intermediate

Answer

Save lightweight state to Preferences/SecureStorage (or a file/db) in OnDisappearing or the window Stopped event, and restore it in OnAppearing/Resumed or at startup. For navigation state and drafts, serialize what's needed so a cold start can resume the user's context.
// Save on stop
Preferences.Default.Set("draft", editor.Text);
// Restore on start
editor.Text = Preferences.Default.Get("draft", string.Empty);
Real-world example A compose screen restores an unfinished message after the OS kills the app in the background.

Common follow-ups: Where do you save state? | What survives a cold start?