Capturing IntentService Intents before onHandleIntent
I have an IntentService which queues up web service calls to be made. I pass an integer as an Extra with each Intent which defines the type of web service call to be made.
I'd like to create a situation where, if an Intent to perform a particular web service is passed to the IntentService and an Intent for that same web service already exists in the IntentService queue, the Intent is not processed. Ideally, I'd throw away the In开发者_运维问答tent, but I could also add an Extra to it that lets the code know to skip the Intent once it is handled. As Intents come in, I could keep track of which ones are in the queue in some object I add to the IntentService.
However, I don't see a place to intercept the Intent right when it is passed to the IntentService. As far as I can tell, I can only touch it when onHandleIntent is called and that would be too late.
Any ideas?
Its not strictly speaking advisable, but I'd suggest something like this:
public int onStartCommand (Intent intent, int flags, int startId)
{
// do your intent modification here
//if(intentIsDuplicate(intent))
// make sure you call the super class to ensure everything performs as expected
return super.onStartCommand(intent, flags, startId);
}
Let me know if that works.
精彩评论