Thread
#moko
    Zhiqiang Bian

    Zhiqiang Bian

    1 year ago
    Hi guys! Does Moko support SharedViewModelin androidApp? Consider the situation when an
    activity
    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.😒miling_face_with_tear: ----------- I can simply do
    activity.viewmodel
    in the fragment, so probably
    sharedViewModel
    is unnecessary.
    alex009

    alex009

    1 year ago
    hi! yes, you can use shared view model. with moko viewmodels you can do all that you do with android viewmodels, because moko viewmodel is subclass of android viewmodel.
    getViewModel
    is additional function, you can ignore it and do viewmodel inject like you do in regular android app. or you can use
    requiredActivity().getViewModel { ... }