android - 在 onHandleIntent 之前捕获 IntentService Intent

标签 android intentservice

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

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

但是,当 Intent 传递给 IntentService 时,我看不到可以拦截它的地方。据我所知,我只能在调用 onHandleIntent 时触摸它,那已经太晚了。

有什么想法吗?

最佳答案

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

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

如果可行,请告诉我。

关于android - 在 onHandleIntent 之前捕获 IntentService Intent ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7381915/

相关文章:

java - 我如何知道Eclipse、Android SDK中的异常是什么?

android - 使用 SDL 1.3 和 OpenGL ES 1.1 的白色纹理

Android OneTime IntentService 在应用程序被杀死时死亡

Android停止指定的IntentService

java - Intent 服务并发

java - 使用AppCompatAcitvity时无法获取Context

java - 在 kotlin 中将 String 转换为 JsonObject 返回 null

php - 如何使用 Retrofit 2 和 php 作为后端在一个请求中上传多张图片?

android - 为什么服务不工作 "immediately"?