lib) returns a new instance of the retrieved viewmodel as opposed to returning the same viewmodel scoped to a navigation graph where it is first retrieved. Any ideas what I might be missing?
c
Colton Idle
08/18/2021, 10:28 PM
Got any code to show? I believe that it should give you back the same instance if that instance is still around, else it will create a new one.
s
Smorg
08/18/2021, 10:34 PM
Thanks @Colton Idle, I am not doing anything special:
Copy code
@HiltViewModel
class MyViewModel @Inject constructor() : ViewModel
...
navigation(route = "root", startDestination="...") {
// Expected: MyViewModel should be the same instance in the composables below
// Actual: MyViewModel is different instances in the comoosables
composable(...) {
hiltViewModel<MyViewModel>
}
composable(...) {
hiltViewModel<MyViewModel>
}
}
...