Android · 2 / 2

Activity lifecycle

States, callbacks and recreation

Activity callbacks describe creation, visibility and interaction states. They are not a mandatory one-way sequence: an Activity can resume, and process termination can skip final callbacks. Lifecycle.

Main callbacks

A normal first entry is onCreate → onStart → onResume. Full coverage by another Activity normally leads to onPause → onStop; returning from stopped calls onRestart before onStart. Never rely on onDestroy for the only copy of important data. Activity API.

Resumed does not mean the only focused window: Android 10 (API 29)+ supports multiple resumed activities in multi-window. An ordinary dialog hosted by the same Activity is different from launching a dialog-themed Activity. Multi-window lifecycle.

Configuration changes

By default, relevant configuration changes recreate the Activity. A ViewModel obtained through its retained owner survives this recreation; an ordinary Activity field or manually constructed ViewModel() does not gain that retention automatically. Process death destroys the ViewModel instance. ViewModel.

Use saved state for small reconstruction inputs and persistent storage for durable data. SavedStateHandle restores values into a new instance; it does not keep the old ViewModel alive. Save UI states.

On Android 9+ with targetSdk >= 28, onSaveInstanceState, if called, runs after onStop. Earlier targets follow the older ordering. Finishing the Activity does not require this callback. Method contract.