pub enum Lifecycle {
WillLaunch,
DidLaunch,
DidBecomeActive,
WillResignActive,
WillEnterForeground,
DidEnterBackground,
DidReceiveMemoryWarning,
WillTerminate,
}Expand description
An app-lifecycle phase (docs/lifecycle.md). Each backend maps these onto its OS’s native app /
activity delegate. Some phases only exist on some platforms — a mobile app truly enters the
background and can be low on memory, a desktop app essentially cannot — so Lifecycle::is_universal
marks the ones every backend delivers, and Toolkit::supports_lifecycle reports per-backend truth.
Rough native mapping:
| phase | AppKit | UIKit | GTK | Qt | Android | XAML |
|---|---|---|---|---|---|---|
WillLaunch / DidLaunch | applicationWill/DidFinishLaunching | same | startup/mount | mount | onCreate | window create |
DidBecomeActive | didBecomeActive | didBecomeActive | notify::is-active | ApplicationActive | onResume | Activated |
WillResignActive | willResignActive | willResignActive | notify::is-active | ApplicationInactive | onPause | Deactivated |
WillEnterForeground | — | willEnterForeground | — | — | onStart | — |
DidEnterBackground | — | didEnterBackground | — | — | onStop | — |
DidReceiveMemoryWarning | — | didReceiveMemoryWarning | — | — | onTrimMemory | — |
WillTerminate | willTerminate | willTerminate | shutdown | aboutToQuit | onDestroy | window close |
Variants§
WillLaunch
Before the window and UI are built — the first thing to run. Set up global state here.
DidLaunch
The UI is mounted and the app is about to start running. Kick off startup work here.
DidBecomeActive
The app came to the foreground and is the active, focused app receiving input.
WillResignActive
The app is about to stop being active (an interruption, app switch, or losing focus).
WillEnterForeground
The app is about to return to the foreground (mobile). Refresh what background invalidated.
DidEnterBackground
The app left the foreground and is no longer visible (mobile). Persist state, release UI work.
DidReceiveMemoryWarning
The system is low on memory (mobile). Drop caches and non-essential memory now.
WillTerminate
The app is about to terminate — the last chance to save. Triggered by the Quit command, the platform’s quit shortcut, or the OS reclaiming the app.
Implementations§
Source§impl Lifecycle
impl Lifecycle
Sourcepub const ALL: [Lifecycle; 8]
pub const ALL: [Lifecycle; 8]
Every phase, in delivery order (launch → run → quit). Handy for logging/registration sweeps.
Sourcepub const fn is_universal(self) -> bool
pub const fn is_universal(self) -> bool
True for phases EVERY backend delivers (launch, activation, termination). The remaining
phases (WillEnterForeground, DidEnterBackground, DidReceiveMemoryWarning) are genuine
mobile concepts and are only delivered by the mobile backends. const so it composes into a
backend’s const fn lifecycle_supported and thus into compile-time guards.