Pranay
Pranay

Reputation: 93

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

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?

Upvotes: 5

Views: 6634

Answers (2)

Yuri Schimke
Yuri Schimke

Reputation: 13488

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

Upvotes: 3

ungrandroi
ungrandroi

Reputation: 1

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)

Upvotes: 0

Related Questions