0

I am working on an app that runs a background services which reads accelerometer (and also sometimes, gyroscope) data in the background continuously. I use partial wake lock but there's battery drain. Is there any way I can reduce or minimize the battery drain? I've seen services like Skype and Whatsapp run in the background and consume very little battery, how do they achieve low battery usage?

1 Answers1

1

One solution seems possible to me: do not use the wakelock for such purpose.

If you want to ensure that you do not miss critical accelerometer event, you have to specify a higher rate for it, though I think that normal and UI rates would be enough.

Receiving events from sensor via a registered listener is already a battery drain. But acquiring a wakelock in addition to it is a certain battery killer.

I've seen services like Skype and Whatsapp run in the background and consume very little battery, how do they achieve low battery usage?

That is too broad to be answered.

Drew
  • 3,307
  • 22
  • 33
  • Higher or lower rate isn't an issue, I have read that a background service gets stopped when the phone enters deep sleep or something. I don't want that to happen, or at least want to know if there's a way I can start the service again when the accelerometer detects a big change in motion? – user3573421 Apr 28 '14 at 08:37
  • If you want to ensure your service is not killed, use [startForeground](https://developer.android.com/reference/android/app/Service.html#startForeground%28int,%20android.app.Notification%29). In this case Android will consider the service important to user, and thus will not attempt to kill it. But that would also require you to supply an ongoing [Notification](https://developer.android.com/reference/android/app/Notification.html). – Drew Apr 28 '14 at 08:48