# CreationExtras

Artifact: [androidx.lifecycle:lifecycle-viewmodel](https://developer.android.com/jetpack/androidx/releases/lifecycle) [View Source](https://cs.android.com/search?q=file:androidx/lifecycle/viewmodel/CreationExtras.kt+class:androidx.lifecycle.viewmodel.CreationExtras) Added in [2.5.0](https://developer.android.com/jetpack/androidx/releases/lifecycle#2.5.0)

*** ** * ** ***


```
public abstract class CreationExtras
```

<br />

Known direct subclasses [CreationExtras.Empty](https://developer.android.com/reference/androidx/lifecycle/viewmodel/CreationExtras.Empty), [MutableCreationExtras](https://developer.android.com/reference/androidx/lifecycle/viewmodel/MutableCreationExtras)

|---|---|
| `https://developer.android.com/reference/androidx/lifecycle/viewmodel/CreationExtras.Empty` | An empty read-only `https://developer.android.com/reference/androidx/lifecycle/viewmodel/CreationExtras`. |
| `https://developer.android.com/reference/androidx/lifecycle/viewmodel/MutableCreationExtras` | A modifiable `https://developer.android.com/reference/androidx/lifecycle/viewmodel/CreationExtras` that holds pairs of `https://developer.android.com/reference/androidx/lifecycle/viewmodel/CreationExtras.Key` and `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html`, allowing efficient value retrieval for each key. |

*** ** * ** ***

A map-like object holding pairs of `https://developer.android.com/reference/androidx/lifecycle/viewmodel/CreationExtras.Key` and `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html`, enabling efficient value retrieval for each key. Each key in `https://developer.android.com/reference/androidx/lifecycle/viewmodel/CreationExtras` is unique, storing only one value per key.

`https://developer.android.com/reference/androidx/lifecycle/viewmodel/CreationExtras` is used in `https://developer.android.com/reference/androidx/lifecycle/ViewModelProvider.Factory#create(kotlin.reflect.KClass,androidx.lifecycle.viewmodel.CreationExtras)` to provide extra information to the `https://developer.android.com/reference/androidx/lifecycle/ViewModelProvider.Factory`. This makes `https://developer.android.com/reference/androidx/lifecycle/ViewModelProvider.Factory` implementations stateless, simplifying factory injection by not requiring all information at construction time.

This abstract class supports read-only access; use `https://developer.android.com/reference/androidx/lifecycle/viewmodel/MutableCreationExtras` for read-write access.

## Summary

| ### Nested types |
|---|
| `public static class https://developer.android.com/reference/androidx/lifecycle/viewmodel/CreationExtras.Empty extends https://developer.android.com/reference/androidx/lifecycle/viewmodel/CreationExtras` An empty read-only `https://developer.android.com/reference/androidx/lifecycle/viewmodel/CreationExtras`. |
| `public interface https://developer.android.com/reference/androidx/lifecycle/viewmodel/CreationExtras.Key<T extends https://developer.android.com/reference/java/lang/Object.html>` Key for the elements of `https://developer.android.com/reference/androidx/lifecycle/viewmodel/CreationExtras`. |

| ### Public methods |
|---|---|
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/lifecycle/viewmodel/CreationExtras.Key<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | `<T extends https://developer.android.com/reference/java/lang/Object.html> https://developer.android.com/reference/androidx/lifecycle/viewmodel/CreationExtras#Key()()` Returns a unique `https://developer.android.com/reference/androidx/lifecycle/viewmodel/CreationExtras#Key()` to be associated with an extra. |
| `boolean` | `https://developer.android.com/reference/androidx/lifecycle/viewmodel/CreationExtras#equals(kotlin.Any)(https://developer.android.com/reference/java/lang/Object.html other)` Compares the specified object with this `https://developer.android.com/reference/androidx/lifecycle/viewmodel/CreationExtras` for equality. |
| `abstract T` | `<T extends https://developer.android.com/reference/java/lang/Object.html> https://developer.android.com/reference/androidx/lifecycle/viewmodel/CreationExtras#get(androidx.lifecycle.viewmodel.CreationExtras.Key)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/lifecycle/viewmodel/CreationExtras.Key<@https://developer.android.com/reference/androidx/annotation/NonNull T> key)` Returns the value to which the specified `https://developer.android.com/reference/androidx/lifecycle/viewmodel/CreationExtras#get(androidx.lifecycle.viewmodel.CreationExtras.Key)` is associated, or null if this `https://developer.android.com/reference/androidx/lifecycle/viewmodel/CreationExtras` contains no mapping for the key. |
| `int` | `https://developer.android.com/reference/androidx/lifecycle/viewmodel/CreationExtras#hashCode()()` Returns the hash code value for this `https://developer.android.com/reference/androidx/lifecycle/viewmodel/CreationExtras`. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/lifecycle/viewmodel/CreationExtras#toString()()` Returns a string representation of this `https://developer.android.com/reference/androidx/lifecycle/viewmodel/CreationExtras`. |

| ### Extension functions |
|---|---|
| `final boolean` | `https://developer.android.com/reference/androidx/lifecycle/viewmodel/CreationExtrasKt.https://developer.android.com/reference/androidx/lifecycle/viewmodel/CreationExtras#(androidx.lifecycle.viewmodel.CreationExtras).contains(androidx.lifecycle.viewmodel.CreationExtras.Key)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/lifecycle/viewmodel/CreationExtras receiver, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/lifecycle/viewmodel/CreationExtras.Key<@https://developer.android.com/reference/androidx/annotation/NonNull ?> key )` Checks if the `https://developer.android.com/reference/androidx/lifecycle/viewmodel/CreationExtras` contains the given `https://developer.android.com/reference/androidx/lifecycle/viewmodel/package-summary#(androidx.lifecycle.viewmodel.CreationExtras).contains(androidx.lifecycle.viewmodel.CreationExtras.Key)`. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/lifecycle/viewmodel/MutableCreationExtras` | `https://developer.android.com/reference/androidx/lifecycle/viewmodel/CreationExtrasKt.https://developer.android.com/reference/androidx/lifecycle/viewmodel/CreationExtras#(androidx.lifecycle.viewmodel.CreationExtras).plus(androidx.lifecycle.viewmodel.CreationExtras)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/lifecycle/viewmodel/CreationExtras receiver, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/lifecycle/viewmodel/CreationExtras creationExtras )` Creates a new read-only `https://developer.android.com/reference/androidx/lifecycle/viewmodel/CreationExtras` by replacing or adding entries to `https://developer.android.com/reference/androidx/lifecycle/viewmodel/CreationExtras` extras from another `https://developer.android.com/reference/androidx/lifecycle/viewmodel/package-summary#(androidx.lifecycle.viewmodel.CreationExtras).plus(androidx.lifecycle.viewmodel.CreationExtras)`. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/lifecycle/SavedStateHandle` | `@https://developer.android.com/reference/androidx/annotation/MainThread https://developer.android.com/reference/androidx/lifecycle/viewmodel/SavedStateHandleSupport.https://developer.android.com/reference/androidx/lifecycle/viewmodel/CreationExtras#(androidx.lifecycle.viewmodel.CreationExtras).createSavedStateHandle()( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/lifecycle/viewmodel/CreationExtras receiver )` Creates a `https://developer.android.com/reference/androidx/lifecycle/SavedStateHandle` for use in your `https://developer.android.com/reference/androidx/lifecycle/ViewModel`s. |

## Public methods

### Key

```
public static final @NonNull CreationExtras.Key<@NonNull T> <T extends Object> Key()
```

Returns a unique `https://developer.android.com/reference/androidx/lifecycle/viewmodel/CreationExtras#Key()` to be associated with an extra.

### equals

```
public boolean equals(Object other)
```

Compares the specified object with this `https://developer.android.com/reference/androidx/lifecycle/viewmodel/CreationExtras` for equality.

### get

Added in [2.5.0](https://developer.android.com/jetpack/androidx/releases/lifecycle#2.5.0)

```
public abstract T <T extends Object> get(@NonNull CreationExtras.Key<@NonNull T> key)
```

Returns the value to which the specified `https://developer.android.com/reference/androidx/lifecycle/viewmodel/CreationExtras#get(androidx.lifecycle.viewmodel.CreationExtras.Key)` is associated, or null if this `https://developer.android.com/reference/androidx/lifecycle/viewmodel/CreationExtras` contains no mapping for the key.

### hashCode

```
public int hashCode()
```

Returns the hash code value for this `https://developer.android.com/reference/androidx/lifecycle/viewmodel/CreationExtras`.

### toString

```
public @NonNull String toString()
```

Returns a string representation of this `https://developer.android.com/reference/androidx/lifecycle/viewmodel/CreationExtras`. The string representation consists of a list of key-value mappings in the order returned by the `https://developer.android.com/reference/androidx/lifecycle/viewmodel/CreationExtras`'s iterator.

## Extension functions

### CreationExtrasKt.contains

Artifact: [androidx.lifecycle:lifecycle-viewmodel](https://developer.android.com/jetpack/androidx/releases/lifecycle) [View Source](https://cs.android.com/search?q=file:androidx/lifecycle/viewmodel/CreationExtras.kt+function:contains)

```
public final boolean CreationExtrasKt.contains(
    @NonNull CreationExtras receiver,
    @NonNull CreationExtras.Key<@NonNull ?> key
)
```

Checks if the `https://developer.android.com/reference/androidx/lifecycle/viewmodel/CreationExtras` contains the given `https://developer.android.com/reference/androidx/lifecycle/viewmodel/package-summary#(androidx.lifecycle.viewmodel.CreationExtras).contains(androidx.lifecycle.viewmodel.CreationExtras.Key)`.

This method allows to use the `key in creationExtras` syntax for checking whether an `https://developer.android.com/reference/androidx/lifecycle/viewmodel/package-summary#(androidx.lifecycle.viewmodel.CreationExtras).contains(androidx.lifecycle.viewmodel.CreationExtras.Key)` is contained in the `https://developer.android.com/reference/androidx/lifecycle/viewmodel/CreationExtras`.

### CreationExtrasKt.plus

Artifact: [androidx.lifecycle:lifecycle-viewmodel](https://developer.android.com/jetpack/androidx/releases/lifecycle) [View Source](https://cs.android.com/search?q=file:androidx/lifecycle/viewmodel/CreationExtras.kt+function:plus)

```
public final @NonNull MutableCreationExtras CreationExtrasKt.plus(
    @NonNull CreationExtras receiver,
    @NonNull CreationExtras creationExtras
)
```

Creates a new read-only `https://developer.android.com/reference/androidx/lifecycle/viewmodel/CreationExtras` by replacing or adding entries to `https://developer.android.com/reference/androidx/lifecycle/viewmodel/CreationExtras` extras from another `https://developer.android.com/reference/androidx/lifecycle/viewmodel/package-summary#(androidx.lifecycle.viewmodel.CreationExtras).plus(androidx.lifecycle.viewmodel.CreationExtras)`.

The returned `https://developer.android.com/reference/androidx/lifecycle/viewmodel/CreationExtras` preserves the entry iteration order of the original `https://developer.android.com/reference/androidx/lifecycle/viewmodel/CreationExtras`.

Those entries of another `https://developer.android.com/reference/androidx/lifecycle/viewmodel/package-summary#(androidx.lifecycle.viewmodel.CreationExtras).plus(androidx.lifecycle.viewmodel.CreationExtras)` that are missing in `https://developer.android.com/reference/androidx/lifecycle/viewmodel/CreationExtras` extras are iterated in the end in the order of that `https://developer.android.com/reference/androidx/lifecycle/viewmodel/package-summary#(androidx.lifecycle.viewmodel.CreationExtras).plus(androidx.lifecycle.viewmodel.CreationExtras)`.

### SavedStateHandleSupport.createSavedStateHandle

Artifact: [androidx.lifecycle:lifecycle-viewmodel-savedstate](https://developer.android.com/jetpack/androidx/releases/lifecycle) [View Source](https://cs.android.com/search?q=file:androidx/lifecycle/SavedStateHandleSupport.kt+function:createSavedStateHandle)

```
@MainThread
public final @NonNull SavedStateHandle SavedStateHandleSupport.createSavedStateHandle(
    @NonNull CreationExtras receiver
)
```

Creates a `https://developer.android.com/reference/androidx/lifecycle/SavedStateHandle` for use in your `https://developer.android.com/reference/androidx/lifecycle/ViewModel`s.

This function requires a call to `https://developer.android.com/reference/androidx/lifecycle/package-summary#(androidx.savedstate.SavedStateRegistryOwner).enableSavedStateHandles()` during component initialization. Modern Jetpack components (such as `ComponentActivity`, `Fragment`, and `NavBackStackEntry`) perform this call automatically.

The `https://developer.android.com/reference/androidx/lifecycle/viewmodel/CreationExtras` must contain `https://developer.android.com/reference/androidx/lifecycle/package-summary#SAVED_STATE_REGISTRY_OWNER_KEY()`, `https://developer.android.com/reference/androidx/lifecycle/package-summary#VIEW_MODEL_STORE_OWNER_KEY()`, and `https://developer.android.com/reference/androidx/lifecycle/ViewModelProvider.Companion#VIEW_MODEL_KEY()`.

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/lifecycle/SavedStateHandle` | new `https://developer.android.com/reference/androidx/lifecycle/SavedStateHandle` instance |

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-argument-exception/index.html` | If the `https://developer.android.com/reference/androidx/lifecycle/viewmodel/CreationExtras` is missing any of the required keys: `https://developer.android.com/reference/androidx/lifecycle/package-summary#VIEW_MODEL_STORE_OWNER_KEY()`, `https://developer.android.com/reference/androidx/lifecycle/package-summary#SAVED_STATE_REGISTRY_OWNER_KEY()`, or `https://developer.android.com/reference/androidx/lifecycle/ViewModelProvider.Companion#VIEW_MODEL_KEY()`. |