Flutter CoreEasy20 XP3 min read
What are Flutter's AppLifecycleState values and when do they trigger?
TL;DR: AppLifecycleState has four values: resumed (visible and active), inactive (visible but not focused, e.g., phone call), paused (in background, not visible), and detached (engine running, no view).
Full Answer
| Aspect | State | Meaning |
|---|---|---|
| resumed | App is visible and responding to user input | Normal active state |
| inactive | App is visible but not focused (iOS: Spotlight, phone call) | Pause heavy work |
| paused | App in background, not visible | Save state, stop updates |
| detached | Engine running without a view | During app termination flow |
🎯
Use WidgetsBindingObserver mixin and override didChangeAppLifecycleState to respond to lifecycle changes. Common use case: pause video playback when paused, resume when resumed.
Code Examples
dartObserving app lifecycle changes
Output
Console prints appropriate message when app changes lifecycle state.
Interview Tip
💡
Always remove the observer in dispose() to avoid memory leaks. The observer pattern here mirrors Android's onResume/onPause lifecycle methods.
#lifecycle#applifecyclestate#resumed#paused#inactive