Google is committed to advancing racial equity for Black communities. See how.

UiSavedStateRegistry

interface UiSavedStateRegistry
androidx.ui.savedinstancestate.UiSavedStateRegistry

Allows components to save and restore their state using the saved instance state mechanism.

Summary

Public methods
abstract Boolean
canBeSaved(value: Any)

Returns true if the value can be saved using this Registry.

abstract Any?

Returns the restored value for the given key.

abstract Map<String, Any>

Executes all the registered value providers and combines these values into a key-value map.

abstract Unit
registerProvider(key: String, valueProvider: () -> Any?)

Registers the value provider.

abstract Unit

Unregisters the value provider previously registered via registerProvider.

Public methods

canBeSaved

abstract 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

abstract 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

abstract fun performSave(): Map<String, Any>

Executes all the registered value providers and combines these values into a key-value map.

registerProvider

abstract fun registerProvider(
    key: String,
    valueProvider: () -> Any?
): Unit

Registers the value provider.

The same key cannot be registered twice, if you need to update the provider call unregisterProvider first and then register again.

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

unregisterProvider

abstract fun unregisterProvider(key: String): Unit

Unregisters the value provider previously registered via registerProvider.

Parameters
key: String Key of the value which shouldn't be saved anymore