Home > Software design >  How to keep running an application in background in Android Wear(Galaxy watch 4) using Kotlin
How to keep running an application in background in Android Wear(Galaxy watch 4) using Kotlin

Time:07-02

I am collecting raw sensor data (HeartRate, accelerometer, gyroscope, etc.) with Samsung Watch 4. I need to run my data collection application continuously in the background. However, it seems the watch OS kills the application after some time.

So my question is - How can I keep my application running in the background continuously without being interrupted/killed by the watch OS?

CodePudding user response:

We had the same problem when using gravity sensor. We tried to keep the screen on to solve it but it's not a ideal way because it will make the power down quickly. Here is the code we used(Java): getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)

CodePudding user response:

Health Services https://developer.android.com/training/wearables/health-services is the way to handle this for heartrate, so you don't need your app to always be running.

But if you need accelerometer and gyro specifically you will need to collect yourself, then you will have to run a Foreground Service.

https://developer.android.com/guide/components/foreground-services

But if you just want accelerometer and gyro for movement to detect an activity, then WHS can do this for you.

See some of the samples here https://github.com/android/health-samples

  • Related