You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: app/src/main/java/com/example/nav3recipes/passingarguments/injectedviewmodels/InjectedViewModelsActivity.kt
+8Lines changed: 8 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -82,6 +82,14 @@ class InjectedViewModelsActivity : ComponentActivity() {
82
82
}
83
83
entry<RouteB> { key ->
84
84
val viewModel = hiltViewModel<RouteBViewModel, RouteBViewModel.Factory>(
85
+
// Note: We need a new ViewModel for every new RouteB instance. Usually
86
+
// we would need to supply a `key` String that is unique to the
87
+
// instance, however, the ViewModelStoreNavEntryDecorator (supplied
88
+
// above) does this for us, using `NavEntry.contentKey` to uniquely
89
+
// identify the viewModel.
90
+
//
91
+
// tl;dr: Make sure you use rememberViewModelStoreNavEntryDecorator()
92
+
// if you want a new ViewModel for each new navigation key instance.
0 commit comments