I have just started using MVVM in android using kotlin. I have created an Android Service which is just fetching user location. This service runs constantly on background and uses FusedLocationApi to fetch the location. I have been reading articles of using background services with MVVM. The most helpful article I found is this Android Service MVVM communicaton. It says that you have to use repository when android service and view model communicates. But I have also found articles that says that do no use Android Framework classes in View Model (Do not use Android Classes in View Model). I am totally confused that how you communicate android services with activity in MVVM. Either we have to use repository for it or how we can implement it.
Any help will be appreciated,
I think the post that you linked above is trying to say: - Service has instance of the repository - ViewModel has instance of the repository - When data changes in service it needs to trigger repository (set new value there) - This will trigger listeners in view model automatically because it is live data or it is some other reactive (observable) data source
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With