Best practice for Android MVVM startActivity

前端 未结 6 1245
你的背包
你的背包 2021-01-30 13:16

I am building an Android App using MVVM and DataBinding. And I have a function inside my ViewModel that starts an Activity. Is it okay to have an onClick call inside a ViewModel

6条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-30 13:26

    That's absolutely perfect to put it inside ViewModel, however you need to set your ViewModel from Activity/Fragment.

    Here are some links you can follow to learn MVVM architecture.

    Approaching Android with MVVM
    Android MVVM
    https://github.com/ivacf/archi
    People-MVVM
    MVVM on Android: What You Need to Know

提交回复
热议问题