nglauber
07/05/2021, 3:06 PMScreenA which is using MyViewModel instantiated using hiltViewModel() function.
ScreenA calls ScreenB. I want to share MyViewModel between both screens. However, I’m popping ScreenA when I’m calling ScreenB.
Is there a way to do this without create a custom ViewModelStoreOwner? 🤔
cc: @Ian Lakejulioromano
07/05/2021, 3:07 PMnglauber
07/05/2021, 3:08 PMjulioromano
07/05/2021, 3:09 PMNavHost {
navigation(route = "myNestedGraph") {
composable { // ScreenA
val vm = hiltViewModel<MyViewModel>(viewModelStoreOwner = navController.getBackStackEntry("myNestedGraph"))
}
composable { // ScreenB
// Get the vm in the same way.
}
}
}nglauber
07/05/2021, 3:51 PM