捕获IntentService意图之前onHandleIntent [英] Capturing IntentService Intents before onHandleIntent

查看:146
本文介绍了捕获IntentService意图之前onHandleIntent的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个IntentService这排队的Web服务调用进行。我的整数关口作为一个额外的每个意图它定义进行Web服务调用的类型。

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.

我想创建的情况下,如果意图来执行特定web服务传递给IntentService和一个Intent该相同的web服务中已经存在IntentService队​​列中,意图不被处理。理想情况下,我会扔掉的意图,但我还可以增加一个额外的给它,它让code知道跳过意图一旦被处理。由于意图进来,我可以跟踪哪些的是在某个对象我添加到IntentService队​​列中。

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.

不过,我不明白的地方拦截意图权当它被传递到IntentService。至于我可以告诉大家,我只能触摸它时onHandleIntent被调用,这将是太晚了。

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.

任何想法?

推荐答案

它不是严格意义上讲可取的,但我认为是这样的:

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

让我知道,如果工程。

这篇关于捕获IntentService意图之前onHandleIntent的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆