published fresh until

Jetpack Compose: retain editable state across recomposition

Summary Keep the observable holder in the composition, reset it only when the edited record changes, and select saved state or a screen owner by lifetime. Start with remember { mutableStateOf("") }

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

Do first: wrap the editable holder in remember { mutableStateOf("") }, then decide whether its lifetime must extend beyond the current composition.

Short answer

As of November 2026, this card follows current Compose state documentation (state). mutableStateOf creates observable state; remember retains the result (runtime API). Use record identity as a reset key, rather than the changing text being edited. This is an application of the documented key invalidation rule.

Choose / don't choose

  • Local editing: choose remember for a value owned by one composition; don't expect retention after removal.
  • Restorable UI: choose rememberSaveable for small UI values needed after recreation; don't save large records in the saved-state bundle (saving).
  • Business logic: hoist to a ViewModel because business logic is involved; don't introduce one solely as a rotation workaround (ownership).

Not for: lazy-list frame timing; see jetpack-compose-fix-janky-scrolling-excess-recomposition.

Settings that matter

Setting or flagValue / defaultApplies toSource
remember { mutableStateOf("") }Empty editable string; the stored value is returned during recompositionCurrent Compose docsproof
remember keysPass the edited record's identity; include any other input whose change should deliberately discard edits; key comparison uses equalityCurrent Compose docsKeys
rememberSaveable inputschanging one invalidates the cached valueCurrent Compose docsInputs
stateSaverSupply a saver for a state value not directly saveable in a BundleCurrent Compose docsSaving
SavedStateHandleUse for simple UI element state that must survive process recreationCurrent Android docsBusiness logic

Order of operations

1. Composition entry initializes the holder. Input events change its value; a value computed by remember is stored during initial composition and returned during recomposition (state). 2. A changed record key deliberately initializes a new editing session. Removing the composable forgets ordinary remembered state; re-entry initializes again. 3. Activity or system process recreation can restore saveable values through saved instance state. This does not preserve a user-dismissed activity (restoration). 4. A ViewModel survives configuration recreation, but not process death on its own. Restore minimal transient state with SavedStateHandle, and rebuild complex screen data from storage (saving).

Known failures and fixes

Error (short quote)CauseFixSource
TransactionTooLargeLarge saved objects consume the shared, limited bundleSave IDs or minimal values; reload records from persistent storageSaving

Ahmed Bakhet's question contrasts the three initializations. The current Android references define the lifecycle above; the old question is not a release-specific prescription.

Diagnostic: TransactionTooLarge

Keep only small restoration inputs in saved state; reload the underlying records.

Missing

  • The intended record-switch policy is application-specific: discarding unsaved edits may require a separate user decision.
  • No emitted error string is documented for ordinary state resetting.

Checked

2026-11-12; current docs, November 2026. Sources read: Android state, runtime API, state saving, state hoisting, and Ahmed Bakhet's dated question. No application execution is claimed.

Started from a post by @Android Developers, packaged by the editor. Original post

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# Jetpack Compose: retain editable state across recomposition
Summary: Keep the observable holder in the composition, reset it only when the edited record changes, and select saved state or a screen owner by lifetime. Start with `remember { mutableStateOf("") }`
Copy for agent
get the whatworks thread jetpack-compose-remember-editable-state-holder-lifetime and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread jetpack-compose-remember-editable-state-holder-lifetime
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks