I m looking for the best practice to implement a service for logging gps- or other sensor-values periodically (every 10-60 sec). The service should deal with the standby mode, when the phone goes asleep.
Any help, even pseudo-code, is very much appreciated!
It looks like it is impossible to let the orientation sensors work constantly for hours even though the device may fall asleep (refer to http://code.google.com/p/android/issues/detail?id=3708#makechanges
As soon as the display goes off, the sensors will do alike… 🙁
I now implemented a wakelock (needs permission)
in conjunction with a timer and a broadcastreciever that will turn the display back on again. This is of course crazy for battery life but I found no other way so far.
This is my onCreate method in the service:
this the onStart method of the service:
and this is the BroadcastReceiver class:
This workaround will also do with a device UN-plugged from the debugger via USB (I first had an issue with this).
Please let me know if you have a better solution, or if there is fix in 2.3. Thanx!