SavedStateHandleDelegateKt
public final class SavedStateHandleDelegateKt
Summary
Public methods |
|
|---|---|
static final @NonNull ReadWriteProperty<Object, @NonNull T> |
<T extends Object> savedNullable(Returns a property delegate that uses |
static final @NonNull ReadWriteProperty<Object, @NonNull T> |
<T extends Object> savedNullable(Returns a property delegate that uses |
Public methods
savedNullable
public static final @NonNull ReadWriteProperty<Object, @NonNull T> <T extends Object> savedNullable(
@NonNull SavedStateHandle receiver,
String key,
@NonNull SavedStateConfiguration configuration,
@NonNull Function0<@NonNull T> init
)
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 | |
|---|---|
String key |
An optional |
@NonNull SavedStateConfiguration configuration |
The |
@NonNull Function0<@NonNull T> init |
The function to provide the initial value of the property. |
| Returns | |
|---|---|
@NonNull ReadWriteProperty<Object, @NonNull T> |
A property delegate that manages the saving and restoring of the value. |
savedNullable
public static final @NonNull ReadWriteProperty<Object, @NonNull T> <T extends Object> savedNullable(
@NonNull SavedStateHandle receiver,
@NonNull <Error class: unknown class><@NonNull T> serializer,
String key,
@NonNull SavedStateConfiguration configuration,
@NonNull Function0<@NonNull T> init
)
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 | |
|---|---|
@NonNull <Error class: unknown class><@NonNull T> serializer |
The KSerializer to use for serializing and deserializing the value. |
String key |
An optional |
@NonNull SavedStateConfiguration configuration |
The |
@NonNull Function0<@NonNull T> init |
The function to provide the initial value of the property. |
| Returns | |
|---|---|
@NonNull ReadWriteProperty<Object, @NonNull T> |
A property delegate that manages the saving and restoring of the value. |