Skip to content
AndroidTesters
Building Android apps

How to restore Jetpack Compose screen state after process death

A recreated process should return users to useful screen context without treating temporary UI state as permanent data. Compare Compose saveable state, SavedStateHandle, and durable storage, then choose what to restore and how to test it.

Written byAndroidTesters Editorial

6 min read

A developer uses a smartphone to check an app screen at a desk.
Photo by SHVETS production on Pexels
In this article
  1. Know what process restoration can and cannot do
  2. Choose the right storage for each piece of state
  3. Implement restoration without duplicating your source of truth
  4. Test the user journey and choose a recovery policy
  5. Frequently asked questions
  6. Key takeaways
At a glance
  • Use rememberSaveable for small, temporary UI state that should survive recreation.
  • Use SavedStateHandle when a ViewModel needs to restore screen inputs or identifiers.
  • Use a database or other persistent source for durable data and meaningful drafts.
  • Restore identifiers and context, then reload large or authoritative data.

To restore a Jetpack Compose screen after process death, save only the small pieces of state needed to rebuild the screen, and keep durable app data in persistent storage. Android may recreate a process with saved instance state, but restoration is not a substitute for storing information that must survive independently of that saved state.

The practical choice depends on what the state means, how long it matters, and how much data it contains. Use the distinctions below to decide what to save, where to save it, and how to verify that users can resume a screen.

Know what process restoration can and cannot do

When Android recreates an activity with saved state, Compose can restore eligible values associated with that screen. This is different from an ordinary recomposition, and it is not a guarantee that every kind of app exit will restore the same screen.

  • Recomposition: State held by remember usually remains while its composable stays in composition, but it is not designed to survive activity recreation.
  • Configuration change: A ViewModel generally survives recreation of its owner for a configuration change, but it does not by itself survive process death.
  • Process recreation: Saved instance state can restore selected, supported values when Android recreates the activity and provides its saved state.
  • Durable recovery: A database or another persistent store is needed when information must remain available beyond that saved-state handoff.
Note

Do not treat process restoration as a universal promise. A force-stop, task removal, crash, or other exit may not follow the same restoration path. Check current Android documentation for lifecycle details that matter to your app.

Choose the right storage for each piece of state

Classify state by its purpose rather than by the screen where it appears. A selected tab is usually temporary interface context; a saved article or an unfinished order may represent data the user expects to keep.

OptionGood fitSurvivesWatch for
rememberShort-lived UI detailsRecomposition while retainedLost on recreation
rememberSaveableSmall Compose UI valuesEligible saved-state restorationBundle size and supported types
SavedStateHandleViewModel screen inputsEligible owner restorationNot a database
Persistent storageDurable records and draftsApp restarts, subject to storage lifecycleLoading, migrations, and consistency
Tip

Save a record ID, search query, selected filter, or small form value when that is enough to reconstruct the screen. Load the full record from its repository instead of copying a large object into saved state.

rememberSaveable is useful for values such as a query field, expanded section, or supported scroll state. For a custom type, provide a suitable Saver that converts it to saveable data, or save a stable identifier and rebuild the object. Saved state has practical size limits, so keep it small.

Implement restoration without duplicating your source of truth

For a simple screen, Compose-managed state can be sufficient. When screen state belongs with a ViewModel, use saved inputs to recreate the ViewModel’s UI state, while the repository remains responsible for durable app data.

  1. List what users need to resume. Identify the minimum context, such as a selected item ID, current filter, or draft text. Leave derived values and reloadable content out of the saved bundle.
  2. Pick the narrowest suitable holder. Use rememberSaveable for local UI state; use a ViewModel and SavedStateHandle for screen inputs shared with screen logic. Use a repository backed by persistent storage for data that must outlive the screen’s saved-state handoff.
  3. Rebuild from saved inputs. On recreation, read the saved ID or query and request the current data from the repository. Represent loading, success, and failure explicitly so the screen can handle a slow or unavailable source.
  4. Persist important edits deliberately. If losing a draft would matter, write it to durable storage at sensible checkpoints. For frequent edits, consider debouncing writes and making sure a pending write is not the only copy of important work.
  5. Keep ownership clear. Avoid maintaining unrelated copies of the same record in Compose state, a ViewModel, and storage. Let one layer be authoritative, and derive display state from it where practical.

For example, a search screen can restore its query and selected filter, then run the search again. A detail screen can restore an item ID and fetch the latest record. A long form may need a persisted draft if users are expected to return after a longer interruption.

Test the user journey and choose a recovery policy

Test state restoration by reproducing system process recreation, not just by rotating the device or navigating away and back. Confirm which state returns, which data is reloaded, and how the screen behaves if the data source has changed or is temporarily unavailable.

A small software team discusses an app together around a desk.
Photo by cottonbro studio on Pexels
  • Verify that saved values reappear after a supported recreation, and that unsaved values are intentionally reset.
  • Check that restored identifiers still resolve if a record was deleted or access changed.
  • Test empty, loading, and error states when reloading data.
  • Confirm that large lists and domain objects are fetched from their source rather than packed into saved state.
  • Avoid placing credentials or other sensitive secrets in screen saved state; use the appropriate secure storage design.
Restore the context the user needs; reload the data the app owns.
Watch out

A ViewModel surviving a configuration change can make a rotation test look successful even when process-death restoration is broken. Test the saved-state path separately, and do not assume that every exit preserves the task’s state.

Test tools and exact lifecycle behavior can vary across Android versions and app configurations. Use the official Android Developers documentation and Google Play Console Help where relevant, especially if your release or testing workflow depends on a particular platform behavior.

Frequently asked questions

These answers help with common decisions when a Compose screen needs a reliable return path.

Is rememberSaveable enough for process death?

It can restore supported, small values when the screen is recreated with saved instance state. It is not durable storage, and it cannot guarantee restoration after every way an app process or task can end.

Does a ViewModel survive process death?

A ViewModel generally survives configuration changes while its owner remains, but not process death on its own. Use SavedStateHandle for appropriate restorable screen inputs and persistent storage for durable data.

Should I save an entire screen model?

Usually not. Save the minimal inputs needed to rebuild it, such as an identifier or filter, and reload the full model from its source. This keeps saved state small and reduces the risk of restoring stale data.

Should a form draft use saved state or a database?

Use saved state for a small draft that only needs to survive a supported recreation. Use persistent storage when the user should be able to return after a longer interruption or when losing the draft would be costly.

Key takeaways

Choose storage according to how long the information matters and what the app must do to recover it.

  • Use rememberSaveable for small, temporary UI context.
  • Use SavedStateHandle to restore suitable ViewModel inputs, not as a database.
  • Keep durable records and important drafts in persistent storage.
  • Restore identifiers and screen context, reload authoritative data, and test recreation separately from configuration changes.

Shipping a build? Have it tested on real Android devices with AndroidTesters. Learn more

Prepared with AI assistance and checked against AndroidTesters' editorial guidelines. AndroidTesters is not affiliated with Google. Rules and numbers change: confirm important details in the official documentation before you act.