CreationExtras
-
Cmn
abstract class CreationExtras
CreationExtras.Empty |
An empty read-only |
MutableCreationExtras |
A modifiable |
A map-like object holding pairs of CreationExtras.Key and Any, enabling efficient value retrieval for each key. Each key in CreationExtras is unique, storing only one value per key.
CreationExtras is used in ViewModelProvider.Factory.create to provide extra information to the Factory. This makes Factory implementations stateless, simplifying factory injection by not requiring all information at construction time.
This abstract class supports read-only access; use MutableCreationExtras for read-write access.
Summary
Nested types |
|---|
object CreationExtras.Empty : CreationExtrasAn empty read-only |
interface CreationExtras.Key<T : Any?>Key for the elements of |
Public companion functions |
||
|---|---|---|
inline CreationExtras.Key<T> |
Returns an unique |
Cmn
|
Public functions |
||
|---|---|---|
open operator Boolean |
Compares the specified object with this |
Cmn
|
abstract operator T? |
<T : Any?> get(key: CreationExtras.Key<T>)Returns the value to which the specified |
Cmn
|
open Int |
hashCode()Returns the hash code value for this |
Cmn
|
open String |
toString()Returns a string representation of this |
Cmn
|
Extension functions |
||
|---|---|---|
operator Boolean |
CreationExtras.contains(key: CreationExtras.Key<*>)Checks if the |
Cmn
|
operator MutableCreationExtras |
CreationExtras.plus(creationExtras: CreationExtras)Creates a new read-only |
Cmn
|
SavedStateHandle |
Creates |
Cmn
|
Public companion functions
Key
inline fun <T : Any?> Key(): CreationExtras.Key<T>
Returns an unique Key to be associated with an extra.
Public functions
equals
open operator fun equals(other: Any?): Boolean
Compares the specified object with this CreationExtras for equality.
get
abstract operator fun <T : Any?> get(key: CreationExtras.Key<T>): T?
Returns the value to which the specified key is associated, or null if this CreationExtras contains no mapping for the key.
toString
open fun toString(): String
Returns a string representation of this CreationExtras. The string representation consists of a list of key-value mappings in the order returned by the CreationExtras's iterator.
Extension functions
contains
operator fun CreationExtras.contains(key: CreationExtras.Key<*>): Boolean
Checks if the CreationExtras contains the given key.
This method allows to use the key in creationExtras syntax for checking whether an key is contained in the CreationExtras.
plus
operator fun CreationExtras.plus(creationExtras: CreationExtras): MutableCreationExtras
Creates a new read-only CreationExtras by replacing or adding entries to this extras from another creationExtras.
The returned CreationExtras preserves the entry iteration order of the original CreationExtras.
Those entries of another creationExtras that are missing in this extras are iterated in the end in the order of that creationExtras.
createSavedStateHandle
@MainThread
fun CreationExtras.createSavedStateHandle(): SavedStateHandle
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 |