SavedStateRegistryOwnerDelegatesKt

Added in 1.3.0-alpha07

public final class SavedStateRegistryOwnerDelegatesKt


Summary

Public methods

static final @NonNull ReadWriteProperty<Object, @NonNull T>
<T extends Object> saved(
    @NonNull SavedStateRegistryOwner receiver,
    String key,
    @NonNull Function0<@NonNull T> init
)

Returns a property delegate provider that manages the saving and restoring of a value of type T within the SavedStateRegistry of this SavedStateRegistryOwner.

static final @NonNull ReadWriteProperty<Object, @NonNull T>
<T extends Object> saved(
    @NonNull SavedStateRegistryOwner receiver,
    @NonNull <Error class: unknown class><@NonNull T> serializer,
    String key,
    @NonNull Function0<@NonNull T> init
)

Returns a property delegate provider that manages the saving and restoring of a value of type T within the SavedStateRegistry of this SavedStateRegistryOwner.

Public methods

public static final @NonNull ReadWriteProperty<Object, @NonNull T> <T extends Object> saved(
    @NonNull SavedStateRegistryOwner receiver,
    String key,
    @NonNull Function0<@NonNull T> init
)

Returns a property delegate provider that manages the saving and restoring of a value of type T within the SavedStateRegistry of this SavedStateRegistryOwner.

import androidx.activity.ComponentActivity

@Serializable data class User(val id: Int, val name: String)
class MyActivity : ComponentActivity() {
    val user by saved(key = "myKey") { User(id = 123, name = "John Doe") }
}
Parameters
String key

An optional String key to use for storing the value in the SavedStateRegistry. A default key will be generated if it's omitted or when 'null' is passed.

@NonNull Function0<@NonNull T> init

The function to provide the initial value of the property.

Returns
@NonNull ReadWriteProperty<Object, @NonNull T>

A property delegate provider that manages the saving and restoring of the value.

public static final @NonNull ReadWriteProperty<Object, @NonNull T> <T extends Object> saved(
    @NonNull SavedStateRegistryOwner receiver,
    @NonNull <Error class: unknown class><@NonNull T> serializer,
    String key,
    @NonNull Function0<@NonNull T> init
)

Returns a property delegate provider that manages the saving and restoring of a value of type T within the SavedStateRegistry of this SavedStateRegistryOwner.

import androidx.activity.ComponentActivity

@Serializable data class User(val id: Int, val name: String)
class MyActivity : ComponentActivity() {
    val user by
        saved(key = "myKey", serializer = serializer()) { User(id = 123, name = "John Doe") }
}
Parameters
@NonNull <Error class: unknown class><@NonNull T> serializer

The KSerializer to use for serializing and deserializing the value.

String key

An optional String key to use for storing the value in the SavedStateRegistry. A default key will be generated if it's omitted or when 'null' is passed.

@NonNull Function0<@NonNull T> init

The function to provide the initial value of the property.

Returns
@NonNull ReadWriteProperty<Object, @NonNull T>

A property delegate provider that manages the saving and restoring of the value.