I have an application that needs to run the background service regularly, and I use AlarmManager to achieve this behavior. To shorten a long story, it is set to run twice per minute (every 30 seconds), and to complete (basically sleep) takes about 20 seconds.
I use several Android devices for testing (Galaxy SII with 4.1.2, Nexus 4 with 4.2.2 and later with CyanogenMOD 10.1.2 and Nexus 7 with 4.2.2), and they all behave sequentially when connected to USB and debugger
As soon as I disconnect the device and leave it on the table, I noticed that the SOMETIMES service will skip one interval. Looking very carefully at the magazine, I see that the service is sometimes delayed for a certain period of time. If it should work in xx: 05 and xx: 35, I noticed that it starts with xx: 45 (10 seconds later than it should).
The very first thing a service does is to get a partial watchdog lock to ensure that the processor does not fall asleep while it is running - this lock lock is not released until it completely does what it needs to do.
My first thought was that the reason was some kind of resource sharing that caused the behavior (there are other processes running with the application), but the service does not even start, it does not even get a tracking lock until 10 seconds later.
It is worth noting that this behavior is most pronounced on Nexus 4, where up to 30% of the data is missing, and on Galaxy SII and Nexus 7 (about ~ 2%), it is significantly less, but this is still worrying, because the inexplicable behavior.
source share