App lifecycle
The foreground, background, suspended, and stopped states your app crosses as people switch away, return, or the OS kills it.
See it
What it is
The app lifecycle is the sequence of states an app moves through as it appears, loses focus, goes into the background, is suspended, and has its process terminated. iOS names the moments applicationDidEnterBackground and applicationDidBecomeActive; Android names them onPause and onResume; the practical question is the same: what must pause, save, refresh, or rebuild when the app's visibility changes?
Use lifecycle events to pause camera or animation work, save a draft, lock sensitive screens, re-read permissions, and reconcile server data when the app becomes active again. Keep this coordination in one place so every screen does not invent a slightly different meaning of foreground.
Gotcha: terminated is not a callback you can depend on. A swipe, crash, memory-pressure kill, battery loss, or OS decision may end the process without giving cleanup code time to run. Save important state as it changes, make startup safe after an abrupt stop, and treat lifecycle events as notifications rather than guaranteed bookends.
Ask AI for it
Add one lifecycle coordinator to this React Native app using AppState. Expose typed active, inactive, and background transitions; pause camera and animation work when leaving active; persist unfinished form state immediately when it changes; and on every return to active re-read runtime permissions, refresh the auth session, and run an idempotent delta sync. Remove the AppState listener during teardown and suppress duplicate transitions. Add a cold-start path that restores only validated persisted state, and tests that simulate backgrounding plus process death without relying on a termination callback.