Zygote
Studyintermediate

Lifecycle cheat sheet

Activity, Fragment and Compose lifecycles on one page: the callbacks, what survives a configuration change, and what survives process death.

6 minAPI 1–37 · 17interactivequizverified 2026-10-27

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 down onPause → onStop → onDestroy.
  • A configuration change destroys and recreates the activity unless you declare otherwise.
  • onSaveInstanceState is the only state that survives process death.
  • A ViewModel survives configuration changes, not process death.
  • In Compose, use LaunchedEffect, DisposableEffect, rememberSaveable and repeatOnLifecycle.

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#

Loading diagram…
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#

CallbackWhenWhat to do
onCreateonce per instanceinflate layout, set up ViewModel, restore saved state
onStartbecoming visibleregister visible-only listeners
onResumegaining focusstart camera, sensors, animations
onPauselosing focuspause playback, commit unsaved edits
onStopno longer visiblerelease heavy resources
onDestroyinstance endingcancel scopes, unregister
onSaveInstanceStatebefore possible deathwrite small, serialisable state
onRestoreInstanceStateafter onStart on recreationread it back

What survives what#

State holderConfig changeProcess death
Activity fieldlostlost
onSaveInstanceState bundlekeptkept
ViewModelkeptlost
SavedStateHandlekeptkept
Room / DataStore / filekeptkept

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#

APIReplaces
LaunchedEffect(key)onStart + coroutine scope
DisposableEffect(key)onStart/onStop pair
rememberSaveableonSaveInstanceState
repeatOnLifecycle(STARTED)manually adding/removing observers
SideEffectpost-composition work

How it evolved#

2008 →Activities onlyonCreate to onDestroy, one screen each.API 1
2011 →FragmentsA second lifecycle nested inside the first.API 11
2017 →Lifecycle-awareLifecycleOwner and observers make state sync automatic.API 21
2021 →ComposeEffects replace callbacks; the lifecycle becomes a dependency.API 21

Curiosity corner#

  • onPause returns before onResume of 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

1 / 12

What does an API level identify?

0 answered · 0 correct

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.

  1. docsThe activity lifecycledeveloper.android.comaccessed 2026-10-27↩
  2. docsالمهام وحزمة التطبيقات الخلفية | App architecturedeveloper.android.comaccessed 2026-10-27↩
  3. docsLifecycle of composablesdeveloper.android.comaccessed 2026-10-27↩
  4. docsGuide to app architecturedeveloper.android.comaccessed 2026-10-27↩