在 onHandleIntent 之前捕获 IntentService Intent

发布于 2024-12-04 02:26:03 字数 447 浏览 1 评论 0原文

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

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

但是,当 Intent 传递给 IntentService 时,我没有看到可以拦截 Intent 的地方。据我所知,我只能在 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 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

唯憾梦倾城 2024-12-11 02:26:03

严格来说,这并不可取,但我建议这样:

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

让我知道这是否有效。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文