I am quite new to Android programming and I wonder what the best approach would be to keep information updated while the screen is off.
The specific situation is as follows: - I use a service that extends Service and implements SensorEventListener. - I use the accelerometer to check if the user is sitting or standing (onSensorChanged). - If the user have been sitting for a specified time the device vibrates and beeps.
The problem is: - The service don't update at a frequency that makes the alarm go of i time. Sometimes is is late by a couple of minutes, sometimes it just updates as I turn the device-screen on. - The update frequency seems to vary between devices.
My question is: - What would be the best approach to solve the problem? Maybe a service isn't the best solution.
My intention is to keep the service running a long time in the background.
Also, I do not want to use a Wake lock because of the battery (which is an important factor in the situation).
// Victor
I mentioned this problem in this blog . I had faced this problem like you. I just found a workaround which I write but it does not work every device. Device's policy for sensors depends on manufacturer and manufacturer limits sensors on cheap phones. ( I don't know why but i guess it is about battery usage)
If you want to use sensors you should use wakelock.(If there is a solution with not using wakelocks, i want to try it)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.