Lifecycle cheat sheet
Activity, Fragment and Compose lifecycles on one page: the callbacks, what survives a configuration change, and what survives process death.
The lifecycle is where most Android bugs are born. This sheet is the reference; the pages explain why.
TL;DR#
- An activity goes
onCreate → onStart → onResume, and back downonPause → onStop → onDestroy. - A configuration change destroys and recreates the activity unless you declare otherwise.
onSaveInstanceStateis the only state that survives process death.- A ViewModel survives configuration changes, not process death.
- In Compose, use
LaunchedEffect,DisposableEffect,rememberSaveableandrepeatOnLifecycle.
Mental model#
The system owns your activity's lifetime; you own its state. Every callback is the system telling you what it is about to do, not asking permission.
Where the analogy breaks#
Unlike a desktop window, an activity can be destroyed while the user still considers the app open. The process is a cache entry, not a session.
The big picture#
Text description of this diagram
An interactive activity lifecycle state machine with event buttons — open, rotate, home, back, open a dialog, start another activity, split screen, and don't keep activities — a live callback log, and a saved-state panel showing what survives each transition.
Deep dive#
Activity#
| Callback | When | What to do |
|---|---|---|
onCreate | once per instance | inflate layout, set up ViewModel, restore saved state |
onStart | becoming visible | register visible-only listeners |
onResume | gaining focus | start camera, sensors, animations |
onPause | losing focus | pause playback, commit unsaved edits |
onStop | no longer visible | release heavy resources |
onDestroy | instance ending | cancel scopes, unregister |
onSaveInstanceState | before possible death | write small, serialisable state |
onRestoreInstanceState | after onStart on recreation | read it back |
What survives what#
| State holder | Config change | Process death |
|---|---|---|
| Activity field | lost | lost |
onSaveInstanceState bundle | kept | kept |
| ViewModel | kept | lost |
SavedStateHandle | kept | kept |
| Room / DataStore / file | kept | kept |
Fragment#
Fragments add onCreateView, onViewCreated, onDestroyView, and the view lifecycle that is
separate from the fragment's own lifecycle. Bind views in onViewCreated and clear the binding in
onDestroyView, or you leak the view hierarchy.
Compose#
| API | Replaces |
|---|---|
LaunchedEffect(key) | onStart + coroutine scope |
DisposableEffect(key) | onStart/onStop pair |
rememberSaveable | onSaveInstanceState |
repeatOnLifecycle(STARTED) | manually adding/removing observers |
SideEffect | post-composition work |
How it evolved#
Curiosity corner#
onPausereturns beforeonResumeof the next activity. It is a handoff, not an end.- Rotation destroys the activity but not the process, which is why a ViewModel survives it.
Try it#
Enable "Don't keep activities" in developer options, then background the app. Every state loss you see is a process-death bug you would have shipped.
Check yourself#
Check yourself
What does an API level identify?
Sources#
Sources
Every version number, API level, class name and date on this page is traced to one of these. Pages are re-verified against them; last_verified above says when.
- docsThe activity lifecycledeveloper.android.comaccessed 2026-10-27↩
- docsالمهام وحزمة التطبيقات الخلفية | App architecturedeveloper.android.comaccessed 2026-10-27↩
- docsLifecycle of composablesdeveloper.android.comaccessed 2026-10-27↩
- docsGuide to app architecturedeveloper.android.comaccessed 2026-10-27↩