6

我有一个 IntentService 排队要进行的 Web 服务调用。我将一个整数作为 Extra 传递给每个 Intent,它定义了要进行的 Web 服务调用的类型。

我想创建一种情况,如果将执行特定 Web 服务的 Intent 传递给 IntentService,并且 IntentService 队列中已经存在同一 Web 服务的 Intent,则不会处理 Intent。理想情况下,我会丢弃 Intent,但我也可以在其中添加一个 Extra,让代码知道在处理后跳过 Intent。当 Intents 进入时,我可以在我添加到 IntentService 的某个对象中跟踪哪些在队列中。

但是,当 Intent 传递给 IntentService 时,我没有看到拦截 Intent 的地方。据我所知,我只能在调用 onHandleIntent 时触摸它,那为时已晚。

有任何想法吗?

4

1 回答 1

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);
}

让我知道这是否有效。

于 2011-09-11T23:26:44.913 回答