WakefulIntentService Updated, Welcomes Its New Donut Overlord
Complaints occasionally rolled in for
stemming from random
WakeLock issues being reported in
For those of you who have no idea what I am talking about,
WakefulIntentService is an
that manages a
WakeLock. Used properly, it ensures that your
AlarmManager work will run to completion without
the device falling back asleep, if you are using a
alarm. This is key for many polling services.
Near as I am able to tell, the problem stemmed
from my use of
onStart() in the service. If the service
were to crash, Android would restart it, but without re-delivering
Intent. As a result, the
WakeLock would never be
acquired, and so it would generate an under-locked exception
when the work was eventually completed.
To combat this, I am discontinuing support for Android 1.6
and older. v0.4.0 of the service now requires API level 5 or
higher, and uses
onStartCommand(). I am trying
semantics now, as that should be enough to prevent these errors.
If that proves to be insufficient, I may fall back to
basically abandoning the current batch of work and waiting
for the next alarm or whatever.
As always, if you have questions or concerns about this
component, please join the
cw-android Google Group
and post there!