SavedStateRegistryOwnerDelegatesKt

Added in 1.3.0-alpha06

public final class SavedStateRegistryOwnerDelegatesKt


Summary

Public methods

static final @NonNull ReadWriteProperty<Object, @NonNull T>
<T extends Object> saved(
    @NonNull SavedStateRegistryOwner receiver,
    @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 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,
    @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 String key,
    @NonNull <Error class: unknown class><@NonNull T> serializer,
    @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,
    @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.

This is a convenience overload that uses the serializer function to obtain the serializer for the reified type T.

The name of the property will be used as the key for storing the value in the SavedStateRegistry.

import androidx.activity.ComponentActivity

@Serializable data class User(val id: Int, val name: String)
class MyActivity : ComponentActivity() {
    val user by saved { User(id = 123, name = "John Doe") }
}
Parameters
@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 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
@NonNull String key

The String key to use for storing the value in the SavedStateRegistry.

@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,
    @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.

This is a convenience overload that uses the name of the property as the key for storing the value in the SavedStateRegistry

import androidx.activity.ComponentActivity

@Serializable data class User(val id: Int, val name: String)
class MyActivity : ComponentActivity() {
    val user by saved(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.

@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 String key,
    @NonNull <Error class: unknown class><@NonNull T> serializer,
    @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 String key

The String key to use for storing the value in the SavedStateRegistry.

@NonNull <Error class: unknown class><@NonNull T> serializer

The KSerializer to use for serializing and deserializing the value.

@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.