Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Acquiring PARTIAL_WAKELOCK every 10 seconds

Is there any problem with an application which acquires a partial wake lock at 10 second intervals. My use-case for this is being able to continually monitor the user's movement via the device accelerometer. Basically, I have a Service which is invoked by an alarm every 10 seconds.

This Service acquires a wake lock, gets some readings from the accelerometer to determine current movement status, and then releases the wake lock. The total lifetime of the service is around 4 seconds.

My understanding is that this leads to the device being kept awake for approx 24 seconds in each minute. While not ideal, I would hope that this is still better practice than holding a constant wake lock for the entire lifetime of my application.

On the other hand, is it possible that the act of acquiring and releasing the wake lock in such a short space of time is just as bad for battery life?

Any input is appreciated.

like image 980
user522210 Avatar asked Apr 13 '11 17:04

user522210


1 Answers

As the comments have indicated, this is really not a good idea. As in "one-star ratings on the Market" type of a not-good idea.

The accelerometer is designed to be used by a running activity (e.g., a game), and that's about it. It is absolutely not designed to be used in the mode in which you are trying.

You are also assuming that the device will fall back asleep immediately upon your release of the WakeLock. That may or may not be true. I would suspect that you will find that you are causing the CPU to be powered on for significantly more than 40% of the available time, even if you are only mandating it to be on for 40%.

I strongly encourage you to view Jeff Sharkey's presentation on power usage in Android from the 2009 Google I|O conference.

like image 189
CommonsWare Avatar answered Sep 24 '22 00:09

CommonsWare