Zhiqiang Bian
08/15/2021, 6:40 PMactivity
holds a fragment
, and I would like to invoke a method of the activity viewmodel
in one of the fragment
.
private val viewModel: lISTViewModel by activityViewModels()
-----------
There is a getViewModel
function in ViewModelFactory
, but I don’t know how to use it.🥲
-----------
I can simply do activity.viewmodel
in the fragment, so probably sharedViewModel
is unnecessary.alex009
08/17/2021, 6:02 AMgetViewModel
is additional function, you can ignore it and do viewmodel inject like you do in regular android app.
or you can use
requiredActivity().getViewModel { ... }