Skip to content

Commit 1a69a09

Browse files
committed
Add comment to basic recipe as well
1 parent 4216769 commit 1a69a09

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

app/src/main/java/com/example/nav3recipes/passingarguments/basicviewmodels/BasicViewModelsActivity.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,14 @@ class BasicViewModelsActivity : ComponentActivity() {
7575
}
7676
}
7777
entry<RouteB> { key ->
78+
// Note: We need a new ViewModel for every new RouteB instance. Usually
79+
// we would need to supply a `key` String that is unique to the
80+
// instance, however, the ViewModelStoreNavEntryDecorator (supplied
81+
// above) does this for us, using `NavEntry.contentKey` to uniquely
82+
// identify the viewModel.
83+
//
84+
// tl;dr: Make sure you use rememberViewModelStoreNavEntryDecorator()
85+
// if you want a new ViewModel for each new navigation key instance.
7886
ScreenB(viewModel = viewModel(factory = RouteBViewModel.Factory(key)))
7987
}
8088
}

app/src/main/java/com/example/nav3recipes/passingarguments/injectedviewmodels/InjectedViewModelsActivity.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ class InjectedViewModelsActivity : ComponentActivity() {
9191
// tl;dr: Make sure you use rememberViewModelStoreNavEntryDecorator()
9292
// if you want a new ViewModel for each new navigation key instance.
9393
creationCallback = { factory ->
94-
println("Creating viewModel for $key")
9594
factory.create(key)
9695
}
9796
)

0 commit comments

Comments
 (0)