I have a Service that loads data from via http request every second.
I am wondering how to implement the service in my current MVVM structure.
A solution I could think of is to:
Viewcalls method fromViewModelViewModelcalls method fromRepository- Start the
Servicein theRepositoryand pass in someLiveData, as Repositories should be responsible for data loading. - Update this
LiveDatain theServiceviapostValue(). - Observe this
LiveDatain UI and notify theViewModelof the changes - In
ViewModelget the changedLiveDataand update the other LiveData for the View accordingly - Stop the
Servicebased on the outcome of step 6
However, I am wondering if there is no better solution with a more direct communication from Service to ViewModel or even from Service to Repository to ViewModel