what is the best practise with view model initiali...
# android
u
what is the best practise with view model initialisation in nested screens ? they are not created by the main activity and thus do not have access to the model data
not kotlin but kotlin colored 2
j
This may be helpful. Always good to check out android documents https://developer.android.com/guide/fragments/communicate#viewmodel
🙌 1
a
you can use shared viewmodel.
*val* sharedVModel:*MainViewModel = viewModel<MainViewModel>(*LocalContext*.current as ComponentActivity)*
in here I am giving context as ComponentActivity so your viewmodel will be live until you destroyed the activity. you can access data in viewmodel from any composeview