Are there any suggestions on how I might extend IntentService to do this? Can the Intent queue of an IntentService be traversed? Or would I need to take the IntentService code and alter it?
Probably the latter, if you really want to examine the actual queue. IntentService
turns the Intents
into messages popped on the message queue of a Looper
via a HandlerThread
. None of that is exposed through the SDK, though. Fortunately, IntentService
is fairly short -- not even 150 lines. You could clone it into your own package and make modifications as needed. Just run a diff on the source when new source updates are released in the AOSP repository, so you know if Google performed any major surgery on IntentService
itself that you might want to take advantage of.
The only other idea I have is to add a table to the database and log which calls are in the queue, with each log being removed from the table when completed.
It wouldn't even need to be persistent like that, since the IntentService
's own queue is not persistent. Just maintain your own FIFO queue in onStartCommand()
, chaining to the superclass, and popping your Intent
off the queue at the end of onHandleIntent()
. This has a chance of getting out of sync with the master queue (e.g., you'll want to use finally
to ensure you pop the work off your own queue), but you wouldn't have to clone the class.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…