在 onHandleIntent 之前捕获 IntentService Intent
我有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
严格来说,这并不可取,但我建议这样:
让我知道这是否有效。
Its not strictly speaking advisable, but I'd suggest something like this:
Let me know if that works.