Skip to main content

Module lifecycle

Module lifecycle 

Source
Expand description

App-lifecycle callbacks (docs/lifecycle.md). An app registers closures for day_spec::Lifecycle phases with on_lifecycle; each backend, at the matching moment in its native app/activity delegate, emits Event::Lifecycle(phase) (or day-core dispatches the launch phases uniformly), and the event pump routes it here to run the closures inside a reactive batch — the same rails as Event::MenuAction, so a lifecycle handler that writes signals updates the UI like any callback.

Not every platform has every phase (a desktop app doesn’t really enter the background), so a handler registered for a phase the running backend doesn’t deliver gets a one-time warning, and apps can guard with lifecycle_supported (runtime) or day::require_lifecycle! (compile time).

Functions§

dispatch_lifecycle
Run every handler registered for phase, in a reactive batch. Called by the event pump on Event::Lifecycle, and directly by launch_with for the launch phases.
lifecycle_supported
Does the running backend deliver phase? Use this to guard registration at runtime: if day::lifecycle_supported(Lifecycle::DidEnterBackground) { on_lifecycle(...) }.
on_lifecycle
Register f to run whenever the app reaches phase. Handlers run in registration order, in a reactive batch (signal writes coalesce into one UI update). Register early — before launch, or at the top of the root builder — so WillLaunch/DidLaunch handlers are in place when they fire.
warn_unsupported_registrations
Warn once for every ALREADY-registered phase the (now-known) backend doesn’t deliver. Called by launch_with right after the backend/tree is installed, covering handlers registered before launch.
Day API ↩ Guides· daybrite.dev