SavedStateDecoderKt
public final class SavedStateDecoderKt
Summary
Public methods |
|
|---|---|
static final @NonNull T |
<T extends Object> decodeFromSavedStateNullable(Decode a serializable object from a |
static final @NonNull T |
<T extends Object> decodeFromSavedStateNullable(Decodes and deserializes the given |
Public methods
decodeFromSavedStateNullable
public static final @NonNull T <T extends Object> decodeFromSavedStateNullable(
@NonNull SavedState savedState,
@NonNull SavedStateConfiguration configuration
)
Decode a serializable object from a SavedState with the default deserializer.
Format not stable: The internal structure of the given SavedState is subject to change in future releases for optimization. While it is guaranteed to be compatible with encodeToSavedState, direct manipulation of its encoded format using keys is not recommended.
import androidx.savedstate.serialization.decodeFromSavedState @Serializable data class User(val id: Int, val name: String) val user = decodeFromSavedState<User>(userSavedState)
| Parameters | |
|---|---|
@NonNull SavedState savedState |
The |
@NonNull SavedStateConfiguration configuration |
The |
| Returns | |
|---|---|
@NonNull T |
The decoded object. |
| Throws | |
|---|---|
SerializationException |
in case of any decoding-specific error. |
kotlin.IllegalArgumentException |
if the decoded input is not a valid instance of |
| See also | |
|---|---|
encodeToSavedState |
decodeFromSavedStateNullable
public static final @NonNull T <T extends Object> decodeFromSavedStateNullable(
@NonNull <Error class: unknown class><@NonNull T> deserializer,
@NonNull SavedState savedState,
@NonNull SavedStateConfiguration configuration
)
Decodes and deserializes the given SavedState to the value of type T using the given deserializer.
Format not stable: The internal structure of the given SavedState is subject to change in future releases for optimization. While it is guaranteed to be compatible with decodeFromSavedState, direct manipulation of its encoded format using keys is not recommended.
import androidx.savedstate.serialization.SavedStateConfiguration import androidx.savedstate.serialization.decodeFromSavedState import androidx.savedstate.serialization.encodeToSavedState val config = SavedStateConfiguration { serializersModule = SerializersModule { polymorphic(Any::class) { subclass(String::class) } } } val value = "foo" val encoded = encodeToSavedState( serializer = PolymorphicSerializer(Any::class), value = value, configuration = config, ) val decoded = decodeFromSavedState( deserializer = PolymorphicSerializer(Any::class), savedState = encoded, configuration = config, )
| Parameters | |
|---|---|
@NonNull <Error class: unknown class><@NonNull T> deserializer |
The deserializer to use. |
@NonNull SavedState savedState |
The |
@NonNull SavedStateConfiguration configuration |
The |
| Returns | |
|---|---|
@NonNull T |
The deserialized object. |
| Throws | |
|---|---|
SerializationException |
in case of any decoding-specific error. |
kotlin.IllegalArgumentException |
if the decoded input is not a valid instance of |
| See also | |
|---|---|
encodeToSavedState |