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
rememberfor a value owned by one composition; don't expect retention after removal. - Restorable UI: choose
rememberSaveablefor small UI values needed after recreation; don't save large records in the saved-state bundle (saving). - Business logic: hoist to a
ViewModelbecause 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 flag | Value / default | Applies to | Source |
|---|---|---|---|
remember { mutableStateOf("") } | Empty editable string; the stored value is returned during recomposition | Current Compose docs | proof |
remember keys | Pass the edited record's identity; include any other input whose change should deliberately discard edits; key comparison uses equality | Current Compose docs | Keys |
rememberSaveable inputs | changing one invalidates the cached value | Current Compose docs | Inputs |
stateSaver | Supply a saver for a state value not directly saveable in a Bundle | Current Compose docs | Saving |
SavedStateHandle | Use for simple UI element state that must survive process recreation | Current Android docs | Business 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) | Cause | Fix | Source |
|---|---|---|---|
TransactionTooLarge | Large saved objects consume the shared, limited bundle | Save IDs or minimal values; reload records from persistent storage | Saving |
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