开发者

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 sp开发者_JS百科ace of time is just as bad for battery life?

Any input is appreciated.


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.


Have you ever used the app MyTracks? http://code.google.com/p/mytracks/

Last I checked, they use a wake lock when the user has an active path.

I have the same issue as you - and while I'd prefer not using a wake lock, my app is ruined if the OS kills the app along the way. Right now we're doing so, at the expense of about 10% battery life per hour - which isn't all that bad. It's certainly not great, but our average path is only about 20 minutes. And it works.

Using the Alarm Manager does seem like a better route. Any good examples of how to use it for this sort of situation?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜