https://kotlinlang.org logo
#android-architecture
Title
# android-architecture
i

Ive Vasiljevic

08/14/2019, 2:14 PM
How would I combine usage of Android Services and MVVM architecture? Should I start the service inside of my activity/fragment class and inside of View Model class listen when service has been connected? Or should I include repo that starts the service and sends data back to View Model observables ?
w

Will Shelor

08/15/2019, 6:24 PM
We handle the service in the repository layer- if the viewmodel subscribes to our livedata and finds the state to be unititalized, it kicks of the request.
Also, our services expose livedata that can be subscribed to
r

rkeazor

08/18/2019, 2:33 PM
I don't think you need to keep any information about the start the service itself in the ViewModel layer just to maintain the integrity of the service. Just start it in the Activity or fragment. what triggers the start of it can be in the Viewmodel layer
6 Views