What is the right place to start a service in MVVM

2019-03-29 07:44发布

问题:

I just started using MVVM architecture on Android. I have a service which basically fetches some data and updates the UI and this is what I understood from MVVM:

  • Activity should not know anything about the data and should take care of the views
  • ViewModels should not know about activity
  • Repository is responsible for getting the data

Now as ViewModels should not know anything about the activity and Activities should not do anything other than handling views, Can anyone please tell where should I start a service?

回答1:

As far as I know, Services are Android related so, they could be started from View (Activity/Fragment/Lifecycleowner).