Config Changes & Process Death Quiz

ANDROID › Lifecycle

An Activity holds a counter in a plain field. After the user rotates the device, the counter resets to zero. What happened?

Answer: Rotation recreated the Activity, so its instance field was cleared

Rotation is a configuration change; by default the system destroys and recreates the Activity, so any state kept only in instance fields is lost.

Which storage option survives a configuration change but is destroyed by system-initiated process death?

Answer: ViewModel

A ViewModel is retained across recreation in memory but lives inside the process, so killing the process for memory destroys it. SavedStateHandle, rememberSaveable, and Room all survive process death.

Why does the framework limit onSaveInstanceState / SavedStateHandle to small, simple data?

Answer: Serialized into a Bundle over a Binder, so oversized data throws TransactionTooLargeException

Saved instance state is serialized into a Bundle on the main thread and crosses a Binder transaction (~1MB limit), so large payloads cause jank or TransactionTooLargeException. Store IDs, not whole objects.

A user swipes your app away from the Recents screen and reopens it. What does the user (and Android) expect to be restored?

Answer: Nothing transient; only persistent storage should remain

Swiping from Recents is a user-initiated dismissal: both ViewModel and saved instance state are discarded. Only persistent storage survives, and the user expects a clean start.

You add android:configChanges="orientation|screenSize" to an Activity. What is the correct expectation?

Answer: Rotation won't recreate it, but process death still needs ViewModel and saved state

configChanges only suppresses recreation for the listed changes (you get onConfigurationChanged and recomposition). It does nothing for process death, so you still need ViewModel plus saved state.

What is the most reliable way to reproduce system-initiated process death while testing?

Answer: Background the app, run adb shell am kill <package>, relaunch from Recents

Backgrounding then killing the process via adb (or the Don't keep activities developer option) simulates the OS reclaiming memory, restoring saved state while discarding the ViewModel. Rotation and finish() are different events.

In an MVVM screen, where should the canonical list of items shown to the user live so it survives both a config change and process death without serialization limits?

Answer: In Room or DataStore, then cached in a ViewModel

Real data belongs in persistent storage (Room/DataStore) which survives everything; the ViewModel caches it in memory for fast access, and saved state holds only a tiny key like a query or scroll position.

The user presses Back to finish your Activity, then relaunches the app from the launcher. Was onSaveInstanceState() called during that finish?

Answer: No, because an explicit finish means nothing needs restoring.

onSaveInstanceState runs when the system might recreate or reclaim the Activity, not when the user explicitly finishes it (Back/finish()); there is nothing the user expects restored, so the framework skips it.

After system-initiated process death, how does a value held in a ViewModel's SavedStateHandle come back?

Answer: It was put in the saved-instance-state Bundle and re-injected on rebuild

SavedStateHandle is backed by the Activity's saved-state registry, so its contents ride in the restored Bundle and are re-injected into a freshly created ViewModel after the process is rebuilt.

In Jetpack Compose, what is the practical difference between remember and rememberSaveable?

Answer: Only rememberSaveable also survives recreation and process death, via the saved-state Bundle

remember only outlives recomposition and is lost on recreation; rememberSaveable additionally stores its value in the saved-instance-state Bundle, so it is restored across config changes and process death.

You wrap a custom data class in rememberSaveable and it crashes at runtime saying the value cannot be saved. What is the fix?

Answer: Make it Bundle-saveable, like Parcelable, or add a custom Saver

rememberSaveable serializes into a Bundle, so the value must be a Bundle-compatible type such as Parcelable, or you must supply a custom Saver that maps it to and from a saveable form.

When is your app's process most likely to be killed by the system specifically to reclaim memory?

Answer: While it is in the background and the system needs memory

The OS reclaims memory by killing low-priority background processes; a foreground app is near the top of the priority list and is rarely targeted, which is why process death almost always strikes a backgrounded app.

Inside onStop()/onDestroy(), how can you tell whether the Activity is going away because of a configuration change rather than a real teardown?

Answer: Call isChangingConfigurations()

Activity.isChangingConfigurations() returns true when the teardown is caused by a configuration change, letting you distinguish it from a genuine finish or process-reclaim destroy.

Why is the 'Don't keep activities' developer option a handy but imperfect way to test process-death restoration?

Answer: It finishes the Activity and clears its ViewModel, but the process stays alive.

The option finishes each backgrounded Activity (clearing its ViewModel and forcing a saved-state restore) but leaves the process alive, so anything held at process scope persists and masks real process-death bugs that an actual kill would expose.

Back to Config Changes & Process Death