I'm trying to make an app on wearOS 3.0 to monitor user exercises. I start from the base project you can find here : https://github.com/android/health-samples/tree/main/health-services/ExerciseSample
In this example, the method bindViewsToService() in ExerciseFragment listens to changes that come from the service.
I added other values in my viewModel and I want them to be saved when the application goes to background for whatever reason. As I use Android Compose, I used variables to keep the ui state and also to know which exercises I give to the user. If the app goes to background and the user comes back to my app, I need it to continue his/her current exercise and not restart everything.
My guess is that I need to save my state currently stored in my viewModel into the ExerciseService to be able to restore it when user comes back. I don't know how I can save it to the service when there is a change and then restore it if the app goes background.
First, is it what I should do? Otherwise, how should I save my state? Do you have ressources on this?
If my explanations aren't clear enough, feel free to ask any clarification!