Acquiring PARTIAL_WAKELOCK every 10 seconds

Are there any problems with the application that receives partial blocking of the trace with an interval of 10 seconds. My precedent for this is the ability to constantly monitor user movement using the device’s accelerometer. Basically, I have a Service that is triggered by an alarm every 10 seconds.

This service receives a trace lock, receives some readings from the accelerometer to determine the current state of movement, and then releases the tracking lock. The total service life of the service is about 4 seconds.

I understand that this leads to the fact that the device does not wake up for about 24 seconds every minute. Although I’m not perfect, I would hope that this is still better than holding a permanent lock on tracking for the entire life of my application.

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

Any input is appreciated.

+4
source share
2 answers

As the comments noted, this is really not a good idea. As in the case of "star ratings in the market" is not a good idea.

The accelerometer is intended for use in action (for example, in a game) and about it. It is absolutely not intended for use in the mode in which you are trying.

You also think that the device will WakeLock asleep immediately after the release of WakeLock . This may or may not be true. I suspect you will find that you are making the processor run on more than 40% of the available time, even if you only assign it 40%.

I highly recommend that you watch Jeff Sharkey’s presentation on Android’s energy consumption from Google’s I | O.

+1
source

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

The last thing I checked, they use locking after the user has an active path.

I have the same problem as you - and although I would prefer not to use tracking lock, my application is destroyed if the OS permanently destroys the application. Right now we are doing this with about 10% of the battery per hour - which is not so bad. This, of course, is not great, but our average path is only about 20 minutes. And it works.

Using the alarm manager seems like the best route. Any good examples of how to use it for this kind of situation?

0
source

Source: https://habr.com/ru/post/1347956/


All Articles