Communication of Android Services with Activity in MVVM (Model View View Model)
Asked Answered
S

1

6

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,

Stenger answered 7/12, 2018 at 17:57 Comment(0)
P
2

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

Paramecium answered 8/6, 2020 at 7:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.