我有一个IntentService,可以对要进行的Web服务调用进行排队。我为每个Intent传递一个整数作为Extra,它定义了要进行的Web服务调用的类型。
我想创建一种情况,如果将执行特定Web服务的Intent传递给IntentService,并且IntentService队列中已存在同一Web服务的Intent,则不会处理Intent。理想情况下,我会丢弃Intent,但我也可以添加一个Extra,让代码知道在处理完Intent后跳过它。当Intent进来时,我可以跟踪我添加到IntentService的某个对象中队列中的哪些。
但是,当它传递给IntentService时,我没有看到拦截Intent的地方。据我所知,我只能在调用onHandleIntent时触摸它,而且为时已晚。
有什么想法吗?
答案 0 :(得分:5)
严格来说,这并不合适,但我建议这样的事情:
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);
}
如果有效,请告诉我。