maui-app-lifecycle

Implements .NET MAUI Window lifecycle events and state preservation across backgrounding and resume transitions.

1|Updated Jun 1, 2026
One-click install
npx skills add https://github.com/D1ssolve/craft-agents --skill maui-app-lifecycle-d1ssolve
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: maui-app-lifecycle
Source: https://github.com/D1ssolve/craft-agents/tree/main/skills/maui-app-lifecycle
Command: npx skills add https://github.com/D1ssolve/craft-agents --skill maui-app-lifecycle-d1ssolve

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Handling app state transitions in .NET MAUI is error-prone: developers lose draft data on backgrounding, confuse Deactivated with Stopped, or miss that Android's back button can skip Stopped entirely. This Skill provides correct patterns for subscribing to Window lifecycle events and preserving state across background and resume cycles. ## Core Features & Use Cases - Window Lifecycle Events: Subscribe to Created, Activated, Deactivated, Stopped, Resumed, and Destroying via CreateWindow overrides or a custom Window subclass. - Platform Lifecycle Mapping: Maps cross-platform events to native callbacks on Android (OnCreate, OnPause), iOS/Mac Catalyst (DidEnterBackground, WillEnterForeground), and Windows (VisibilityChanged, Closed), plus ConfigureLifecycleEvents for direct native hooks. - State Preservation Workflow: Save transient state in OnStopped and OnDestroying using Preferences, then restore it in OnResumed. - Use Case: A user is drafting a message in your MAUI app and switches to another app. Save the draft text and scroll position in OnStopped, restore them in OnResumed, and also save in OnDestroying to handle the Android back-button path. ## Quick Start Use the maui-app-lifecycle skill to add Window lifecycle handlers that save my form draft when the app backgrounds and restore it on resume.

Frequently Asked Questions about maui-app-lifecycle

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I save app state when a .NET MAUI app is backgrounded?

Override OnStopped in a custom Window subclass and persist transient state using Preferences for small values or file serialization for larger data. Also save in OnDestroying because the Android back button can skip Stopped entirely.

What is the difference between Deactivated and Stopped in .NET MAUI?

Deactivated fires when the window loses focus but may still be visible, such as during a dialog or split-screen. Stopped fires only when the window is fully backgrounded and no longer visible, so avoid heavy saves in OnDeactivated.

How do I hook native Android or iOS lifecycle callbacks in .NET MAUI?

Use ConfigureLifecycleEvents in MauiProgram.cs with conditional compilation. Call events.AddAndroid for Activity callbacks like OnCreate and OnStop, events.AddiOS for UIKit callbacks like DidEnterBackground, and events.AddWindows for WinUI callbacks.

Why does OnResumed not fire when my MAUI app first launches?

Resumed only fires when returning from a Stopped state, not on first launch. The initial sequence is Created then Activated, so place logic that must run on every foreground entry in OnActivated instead.

Should I use Application.OnStart and OnSleep in .NET MAUI?

No. OnStart, OnSleep, and OnResume exist only for Xamarin.Forms backward compatibility and bypass Window-level events. Prefer Window lifecycle overrides like OnActivated, OnStopped, and OnResumed for correct multi-window behavior.