# HiltViewModelFactory

Added in 1.0.0

*** ** * ** ***


```
public final class HiltViewModelFactory
```

<br />

*** ** * ** ***

## Summary

| ### Public methods |
|---|---|
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/lifecycle/ViewModelProvider.Factory` | `[create](https://developer.android.com/reference/androidx/hilt/navigation/HiltViewModelFactory#create(android.content.Context,androidx.lifecycle.ViewModelProvider.Factory))( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/content/Context.html context, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/lifecycle/ViewModelProvider.Factory delegateFactory )` **This method is deprecated.** Moved to package: androidx.hilt.lifecycle.viewmodel |
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/lifecycle/ViewModelProvider.Factory` | `https://developer.android.com/reference/androidx/hilt/navigation/HiltViewModelFactory#create(android.content.Context,androidx.navigation.NavBackStackEntry)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/content/Context.html context, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/navigation/NavBackStackEntry navBackStackEntry )` Creates a `https://developer.android.com/reference/androidx/lifecycle/ViewModelProvider.Factory` to get [HiltViewModel](https://dagger.dev/api/latest/dagger/hilt/android/lifecycle/HiltViewModel) -annotated `ViewModel` from a `https://developer.android.com/reference/androidx/navigation/NavBackStackEntry`. |

## Public methods

### create

Artifact: [androidx.hilt:hilt-navigation](https://developer.android.com/jetpack/androidx/releases/hilt) [View Source](https://cs.android.com/search?q=file:androidx/hilt/navigation/HiltNavBackStackEntry.kt+function:HiltViewModelFactory) Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/hilt#1.1.0) Deprecated in [1.3.0](https://developer.android.com/jetpack/androidx/releases/hilt#1.3.0)

```
public static final @NonNull ViewModelProvider.Factory [create](https://developer.android.com/reference/androidx/hilt/navigation/HiltViewModelFactory#create(android.content.Context,androidx.lifecycle.ViewModelProvider.Factory))(
    @NonNull Context context,
    @NonNull ViewModelProvider.Factory delegateFactory
)
```

> [!CAUTION]
> **This method is deprecated.**   
> Moved to package: androidx.hilt.lifecycle.viewmodel, use this instead:
>
> ```
> HiltViewModelFactory(context, delegateFactory)
> ```

Creates a `https://developer.android.com/reference/androidx/lifecycle/ViewModelProvider.Factory` to get [HiltViewModel](https://dagger.dev/api/latest/dagger/hilt/android/lifecycle/HiltViewModel) -annotated `ViewModel` from a `https://developer.android.com/reference/androidx/lifecycle/ViewModelProvider.Factory`.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/content/Context.html context` | the activity context. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/lifecycle/ViewModelProvider.Factory delegateFactory` | the delegated factory. |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/lifecycle/ViewModelProvider.Factory` | the factory. |

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-state-exception/index.html` | if the context given is not an activity. |

### create

Artifact: [androidx.hilt:hilt-navigation](https://developer.android.com/jetpack/androidx/releases/hilt) [View Source](https://cs.android.com/search?q=file:androidx/hilt/navigation/HiltNavBackStackEntry.kt+function:HiltViewModelFactory) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/hilt#1.0.0)

```
public static final @NonNull ViewModelProvider.Factory create(
    @NonNull Context context,
    @NonNull NavBackStackEntry navBackStackEntry
)
```

Creates a `https://developer.android.com/reference/androidx/lifecycle/ViewModelProvider.Factory` to get [HiltViewModel](https://dagger.dev/api/latest/dagger/hilt/android/lifecycle/HiltViewModel) -annotated `ViewModel` from a `https://developer.android.com/reference/androidx/navigation/NavBackStackEntry`.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/content/Context.html context` | the activity context. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/navigation/NavBackStackEntry navBackStackEntry` | the navigation back stack entry. |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/lifecycle/ViewModelProvider.Factory` | the factory. |

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-state-exception/index.html` | if the context given is not an activity. |