Skip to content

Commit e93741c

Browse files
committed
Ensure that separate VMs are created for each new instance of RouteB
1 parent 955a300 commit e93741c

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,12 @@ class BasicViewModelsActivity : ComponentActivity() {
6565
entryProvider = entryProvider {
6666
entry<RouteA> {
6767
ContentGreen("Welcome to Nav3") {
68-
Button(onClick = {
69-
backStack.add(
70-
RouteB("123")
71-
)
72-
}) {
73-
Text("Click to navigate")
68+
for (i in 0 .. 10){
69+
Button(onClick = {
70+
backStack.add(RouteB("$i"))
71+
}) {
72+
Text("$i")
73+
}
7474
}
7575
}
7676
}

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,16 +71,19 @@ class InjectedViewModelsActivity : ComponentActivity() {
7171
entryProvider = entryProvider {
7272
entry<RouteA> {
7373
ContentGreen("Welcome to Nav3") {
74-
Button(onClick = {
75-
backStack.add(RouteB("123"))
76-
}) {
77-
Text("Click to navigate")
74+
for (i in 0 .. 10){
75+
Button(onClick = {
76+
backStack.add(RouteB("$i"))
77+
}) {
78+
Text("$i")
79+
}
7880
}
7981
}
8082
}
8183
entry<RouteB> { key ->
8284
val viewModel = hiltViewModel<RouteBViewModel, RouteBViewModel.Factory>(
8385
creationCallback = { factory ->
86+
println("Creating viewModel for $key")
8487
factory.create(key)
8588
}
8689
)

0 commit comments

Comments
 (0)