SaveableStateRegistry | API reference | Android Developers (original) (raw)
Stay organized with collections Save and categorize content based on your preferences.
- Cmn
interface SaveableStateRegistry
Allows components to save and restore their state using the saved instance state mechanism.
Summary
Public functions
canBeSaved
fun canBeSaved(value: Any): Boolean
Returns true if the value can be saved using this Registry. The default implementation will return true if this value can be stored in Bundle.
Parameters | |
---|---|
value: Any | The value which we want to save using this Registry |
consumeRestored
fun consumeRestored(key: String): Any?
Returns the restored value for the given key. Once being restored the value is cleared, so you can't restore the same key twice.
Parameters | |
---|---|
key: String | Key used to save the value |
performSave
fun performSave(): Map<String, List<Any?>>
Executes all the registered value providers and combines these values into a map. We have a list of values for each key as it is allowed to have multiple providers for the same key.
registerProvider
fun registerProvider(key: String, valueProvider: () -> Any?): SaveableStateRegistry.Entry
Registers the value provider.
There are could be multiple providers registered for the same [key](/reference/kotlin/androidx/compose/runtime/saveable/SaveableStateRegistry#registerProvider%28kotlin.String,kotlin.Function0%29)
. In this case the order in which they were registered matters.
Say we registered two providers for the key. One provides "1", second provides "2". [performSave](/reference/kotlin/androidx/compose/runtime/saveable/SaveableStateRegistry#performSave%28%29)
in this case will have listOf("1", "2) as a value for the key in the map. And later, when the registry will be recreated with the previously saved values, the first execution of [consumeRestored](/reference/kotlin/androidx/compose/runtime/saveable/SaveableStateRegistry#consumeRestored%28kotlin.String%29)
would consume "1" and the second one "2".
Parameters | |
---|---|
key: String | Key to use for storing the value |
valueProvider: () -> Any? | Provides the current value, to be executed when performSave will be triggered to collect all the registered values |
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-05-15 UTC.