Let's say we have an implementation of IntentService
, then we start it from Activity
and then add several other Intent
s in a queue to IntentService
for processing. So now we have first Intent
under processing and the rest of Intent
s in a queue. Now let's imagine the OS kills our Application
process because of understandable reason. The questions are:
How to restart the IntentService
?
How to restore the queue?
Well, I know there is always a Service
where you can override it's onStartCommand()
and tell a Service
what to do. But I need an IntentService
because of its queue
model.
IntentService
is not what you want to use if the queue of work needs to be persistent. If you send many Intent
s to an IntentService
and then the process is killed by Android, there is no way to rebuild the queue. IntentService
simply queues the Intent
s up using an internal Handler
and these are not persisted anywhere. They just get lost.
If I were you I would just implement this myself. The code for IntentService
isn't that large and you can look at it and use it as a model for your own Service
. You'll want to write your queue to a database so that it is persistent. Return START_STICKY
from onStartCommand()
so that Android will automatically restart your Service
if it is killed due to resource requirements.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With