container

fun <STATE : Parcelable, SIDE_EFFECT : Any> ViewModel.container(initialState: STATE, savedStateHandle: SavedStateHandle, buildSettings: SettingsBuilder.() -> Unit = {}, onCreate: suspend Syntax<STATE, SIDE_EFFECT>.() -> Unit? = null): Container<STATE, SIDE_EFFECT>(source)

Creates a container scoped with ViewModelScope and allows you to used the Android ViewModel's saved state support.

Provide a SavedStateHandle in order for your Parcelable state to be automatically saved as you use the container.

Return

A Container implementation

Parameters

initialState

The initial state of the container.

savedStateHandle

The SavedStateHandle corresponding to this host. Typically retrieved from the containing ViewModel

buildSettings

This builder can be used to change the container's settings.

onCreate

The intent to execute when the container is created, provided with the default or recreated state

fun <STATE : Any, SIDE_EFFECT : Any> ViewModel.container(initialState: STATE, buildSettings: SettingsBuilder.() -> Unit = {}, onCreate: suspend Syntax<STATE, SIDE_EFFECT>.() -> Unit? = null): Container<STATE, SIDE_EFFECT>(source)

Creates a container scoped with ViewModelScope.

Return

A Container implementation

Parameters

initialState

The initial state of the container.

buildSettings

This builder can be used to change the container's settings.

onCreate

The intent to execute when the container is created


fun <STATE : Any, SIDE_EFFECT : Any> ViewModel.container(initialState: STATE, savedStateHandle: SavedStateHandle, serializer: KSerializer<STATE>, buildSettings: SettingsBuilder.() -> Unit = {}, onCreate: suspend Syntax<STATE, SIDE_EFFECT>.() -> Unit? = null): Container<STATE, SIDE_EFFECT>(source)

Creates a container scoped with ViewModelScope and allows you to used the Android ViewModel's saved state support.

Provide a SavedStateHandle in order for your Serializable state to be automatically saved as you use the container.

Return

A Container implementation

Parameters

initialState

The initial state of the container.

savedStateHandle

The SavedStateHandle corresponding to this host. Typically retrieved from the containing ViewModel

serializer

The KSerializer to use for serializing and deserializing state.

buildSettings

This builder can be used to change the container's settings.

onCreate

The intent to execute when the container is created, provided with the default or recreated state