How to keep running a Health application in background (wear OS / Kotlin)

Viewed 84

I know that there is similar topic here: How to keep running an application in background in Android Wear(Galaxy watch 4) using Kotlin but I have quite different problem. Here is two type of receiving Health data from sensors: https://github.com/android/health-samples/tree/main/health-services

1 - MeasureData

2 - PassiveData

I need somehow join this two solution into one. There is why:

The first one working perfectly and showing your actual BPM every second. But when you turn your wrist and display is gone (onPause / onStop) - app will stop checking your BPM. When you turn wrist and display is appear - app is appear and BPM is starting show again. I try to keep screen display always on - this work, but battery life is too small (2-3 hours only..)

The second one should work on background, but it is very strange, because when I try it, it show your BPM once upon a time. And I don't figure it out, how to simply checking your BPM every second.

So my question is - can someone help me edit this first (measureData) code to be working also on background? So I can turn my wrist - display is off (we save the battery) and when I look on display - it appear and showing actual BPM. And I need to work on background, because I added there some conditions. If your BPM is above (for example) 150 - my app should go to the foreground and starting beeping (just alert for user).

Or it is possible somehow just turn off function onPause / onStop and this Measure app will continue?

I will be very glad for any help.

0 Answers
Related