androidx.lifecycle.serialization
Extension functions summary
inline ReadWriteProperty<Any?, T> |
<T : Any?> SavedStateHandle.saved(Returns a property delegate that uses |
Cmn
|
ReadWriteProperty<Any?, T> |
<T : Any?> SavedStateHandle.saved(Returns a property delegate that uses |
Cmn
|
Extension functions
saved
inline fun <T : Any?> SavedStateHandle.saved(
key: String? = null,
configuration: SavedStateConfiguration = SavedStateConfiguration.DEFAULT,
noinline init: () -> T
): ReadWriteProperty<Any?, T>
Returns a property delegate that uses SavedStateHandle to save and restore a value of type T with the default serializer.
import androidx.lifecycle.serialization.saved @Serializable data class User(val id: Int, val name: String) class ProfileViewModel(savedStateHandle: SavedStateHandle) : ViewModel() { val user by savedStateHandle.saved(key = "bar") { User(123, "foo") } }
| Parameters | |
|---|---|
key: String? = null |
An optional |
configuration: SavedStateConfiguration = SavedStateConfiguration.DEFAULT |
The |
noinline init: () -> T |
The function to provide the initial value of the property. |
| Returns | |
|---|---|
ReadWriteProperty<Any?, T> |
A property delegate that manages the saving and restoring of the value. |
saved
fun <T : Any?> SavedStateHandle.saved(
serializer: <Error class: unknown class><T>,
key: String? = null,
configuration: SavedStateConfiguration = SavedStateConfiguration.DEFAULT,
init: () -> T
): ReadWriteProperty<Any?, T>
Returns a property delegate that uses SavedStateHandle to save and restore a value of type T.
import androidx.lifecycle.serialization.saved @Serializable data class User(val id: Int, val name: String) class ProfileViewModel(savedStateHandle: SavedStateHandle) : ViewModel() { val user by savedStateHandle.saved(key = "bar", serializer = User::class.serializer()) { User(123, "foo") } }
| Parameters | |
|---|---|
serializer: <Error class: unknown class><T> |
The KSerializer to use for serializing and deserializing the value. |
key: String? = null |
An optional |
configuration: SavedStateConfiguration = SavedStateConfiguration.DEFAULT |
The |
init: () -> T |
The function to provide the initial value of the property. |
| Returns | |
|---|---|
ReadWriteProperty<Any?, T> |
A property delegate that manages the saving and restoring of the value. |