1

我遇到了一个奇怪的情况,我之前为活动识别更新创建了待处理的意图

PendingIntent pendingIntent = PendingIntent.getService(mContext, getIntentID(), intent,
                PendingIntent.FLAG_UPDATE_CURRENT);

我的 getIntentID 代码是

private static int getIntentID(){
    if(intentID == 0)
        return intentID = (int)(System.currentTimeMillis());
    return intentID;
}

我这样做是因为我想确保每次停止和启动服务时 id 都是唯一的。

然而,现在当我在我的 intentService 中阅读正在发送的活动时,我很确定这不是我最近发出请求的未决意向调用。我相信它来自上一个。但是我不知道如何取消它,因为我不知道前一个的 id。1. 为什么不知道之前的id?好吧,当我通过删除更新取消更新时,我确实使用了我认为正常工作的 getIntentID,但是当我停止我的应用程序,再次启动它但没有启动用于活动识别的 update() 代码时,我注意到我仍然得到活动,当我使用调试器时。

这是我的更新请求

ActivityRecognition.ActivityRecognitionApi.requestActivityUpdates(getActivityRecognitionClient(),
            Utility.DETECTION_INTERVAL_TIME, pendingIntent())

这是我的删除代码

 ActivityRecognition.ActivityRecognitionApi.removeActivityUpdates(getActivityRecognitionClient(),
            pendingIntent())

所以我的问题是,有没有办法取消活动识别的所有通话时间。即使我不知道pendingintent 信息?

4

2 回答 2

0

所以我的问题是,有没有办法取消活动识别的所有通话时间。

如果你参考它只包含两种API方法ActivityRecognitionApi

https://developers.google.com/android/reference/com/google/android/gms/location/ActivityRecognitionApi

一种用于请求更新

requestActivityUpdates(GoogleApiClient client, long detectionIntervalMillis, PendingIntent callbackIntent) 

第二个删除更新

removeActivityUpdates(GoogleApiClient client, PendingIntent callbackIntent) 

两种方法都需要PendingIntent

所以显然答案是否定的。

希望这会帮助你。

于 2015-06-27T11:20:59.613 回答
0

好的,似乎没有办法取消活动识别的未决意图。就像 Nag 所说,但是我最终做的是更改我的 intentservice 类的名称并改用它并跟踪待处理的 Id 信息。现在我没有来自以前的电话的任何请求

于 2015-06-28T15:21:55.620 回答