SavedStateHandleSupport
public final class SavedStateHandleSupport
Summary
Public fields |
|
|---|---|
static final @NonNull CreationExtras.Key<@NonNull SavedState> |
A key for default arguments that should be passed to |
static final @NonNull CreationExtras.Key<@NonNull SavedStateRegistryOwner> |
A key for |
static final @NonNull CreationExtras.Key<@NonNull ViewModelStoreOwner> |
A key for |
Public methods |
|
|---|---|
static final @NonNull SavedStateHandle |
@MainThreadCreates |
static final void |
@MainThreadEnables the support of |
Public fields
DEFAULT_ARGS_KEY
public static final @NonNull CreationExtras.Key<@NonNull SavedState> DEFAULT_ARGS_KEY
A key for default arguments that should be passed to SavedStateHandle if needed.
SAVED_STATE_REGISTRY_OWNER_KEY
public static final @NonNull CreationExtras.Key<@NonNull SavedStateRegistryOwner> SAVED_STATE_REGISTRY_OWNER_KEY
A key for SavedStateRegistryOwner that corresponds to ViewModelStoreOwner of a ViewModel that is being created.
VIEW_MODEL_STORE_OWNER_KEY
public static final @NonNull CreationExtras.Key<@NonNull ViewModelStoreOwner> VIEW_MODEL_STORE_OWNER_KEY
A key for ViewModelStoreOwner that is an owner of a ViewModel that is being created.
Public methods
createSavedStateHandle
@MainThread
public static final @NonNull SavedStateHandle createSavedStateHandle(@NonNull CreationExtras receiver)
Creates SavedStateHandle that can be used in your ViewModels
This function requires enableSavedStateHandles call during the component initialization. Latest versions of androidx components like ComponentActivity, Fragment, NavBackStackEntry makes this call automatically.
This CreationExtras must contain SAVED_STATE_REGISTRY_OWNER_KEY, VIEW_MODEL_STORE_OWNER_KEY and VIEW_MODEL_KEY.
| Throws | |
|---|---|
kotlin.IllegalArgumentException |
if this |
enableSavedStateHandles
@MainThread
public static final void <T extends SavedStateRegistryOwner & ViewModelStoreOwner> enableSavedStateHandles(
@NonNull T receiver
)
Enables the support of SavedStateHandle in a component.
After this method, createSavedStateHandle can be called on CreationExtras containing this SavedStateRegistryOwner / ViewModelStoreOwner.
Must be called while component is in INITIALIZED or CREATED state and before a ViewModel with SavedStateHandle is requested.