i have application that's supposed run background service @ regular intervals , i'm using alarmmanager achieve behavior. cut long story short, it's set run twice per minute (every 30 seconds) , takes 20 seconds execute (mostly sleeping).
i using several android devices testing (galaxy sii 4.1.2, nexus 4 4.2.2 , later cyanogenmod 10.1.2 , nexus 7 4.2.2) , of them behave consistently while connected usb , debugger.
once unplug device , leave on desk, notice sometimes service miss 1 interval. looking closely @ log see service delayed period of time. if it's supposed run @ xx:05 , xx:35 i'll notice starting @ xx:45 (10 seconds later should).
the first thing service acquire partial wake lock ensure cpu doesn't go sleep while it's running - wake lock isn't released until it's done it's supposed do.
my first thought was share resource contention causing behavior (there other processes running app) service doesn't start, doesn't acquire wake lock until 10 seconds later.
it's worth mentioning behavior pronounced on nexus 4 30% of data missing, while it's substantially less on galaxy sii , nexus 7 (around ~2%) it's still concern since it's unexplained behavior.
you did not state sort of alarm using, given complaints, assume _wakeup alarm. if so, only guarantee have if use broadcast pendingintent, android keep device awake during call onreceive(). using service pendingintent, doing, unreliable, device fall asleep before service starts , can acquire wakelock.
hence, more reliable pattern _wakeup alarm use broadcast pendingintent, have broadcastreceiver acquire() wakelock, have call startservice() pass control service. service work, releases wakelock.
i have pattern wrapped in my wakefulintentservice component.
Comments
Post a Comment