Capturing IntentService Intents before onHandleIntent

喜欢而已 提交于 2019-12-21 12:38:04

问题


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 Intent, 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?


回答1:


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.



来源:https://stackoverflow.com/questions/7381915/capturing-intentservice-intents-before-onhandleintent

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!