Saveable State Registry
Coordinates values that survive composition disposal and host recreation.
Android hosts connect this registry to androidx.savedstate. Custom hosts install their own registry with ProvideSaveableStateRegistry. Restored values use a claim/commit protocol so an aborted composition cannot consume state that a later attempt still needs.
Samples
val registry = createSaveableStateRegistry(
restoredValues = mapOf("counter" to 3),
canBeSaved = { value -> value == null || value is Int },
)
val restored = checkNotNull(registry.claimRestored("counter"))
check(restored.value == 3)
restored.commit()
var counter = 4
val entry = registry.registerProvider("counter") { counter }
counter = 5
check(registry.performSave()["counter"] == 5)
entry.unregister()Content copied to clipboard
Types
Functions
Link copied to clipboard
Returns whether value can cross the current host's persistence boundary.
Link copied to clipboard
Reserves restored state for one composition attempt.
Link copied to clipboard
Claims and immediately commits a restored value for key.
Link copied to clipboard
Returns a snapshot of restored, retained, claimed, and actively provided values.
Link copied to clipboard
Registers one value provider for key.