简体   繁体   English

Android活动识别示例错误

[英]Android Activity Recognition Sample Bug

So I downloaded the Sample App for 'Recognizing the User's Current Activity' on the android website http://developer.android.com/training/location/activity-recognition.html 因此,我在android网站http://developer.android.com/training/location/activity-recognition.html上下载了“识别用户的当前活动”示例应用程序

The problem I'm having is that when I press the 'Start Updates' button, then the 'Stop Updates' button, and then the 'Start Updates' button again, the updates don't start again the second time. 我遇到的问题是,当我按“开始更新”按钮,然后按“停止更新”按钮,然后再按“开始更新”按钮时,更新不会第二次再次开始。

I've searched online but couldn't find much material on the topic so yeah, I've also tried debugging and found that the onDisconnected() method call (via the ConnectionCallbacks interface) isn't being called in either of the DetectionRemover.java or DetectionRequester.java files. 我已经在线搜索过,但是找不到关于该主题的大量材料,所以,是的,我也尝试调试,发现在两个DetectionRemover中都没有调用onDisconnected()方法调用(通过ConnectionCallbacks接口)。 java或DetectionRequester.java文件。

If anyone knows why this is happening I'd really like to know why. 如果有人知道为什么会这样,我真的很想知道为什么。 From what I've gathered it doesn't seem to be anything in the sample code, and I think it might be a problem on the Google Services side. 根据我的收集,示例代码中似乎没有任何内容,我认为这可能是Google服务方面的问题。

PS I'm using Google Play services rev 16. along with a Samsung galaxy s2 android version 4.1.2 PS我正在使用Google Play服务修订版16,以及Samsung Galaxy S2 Android版本4.1.2

I noticed this same problem running the sample code on my Nexus 4 (Android 4.4.4). 我在Nexus 4(Android 4.4.4)上运行示例代码时发现了同样的问题。 I found that if I commented out the following line of code in the ActivityDetectionRemover continueRemoveUpdates() method, it fixed the problem: 我发现,如果我在ActivityDetectionRemover continueRemoveUpdates()方法中注释了以下代码行,则可以解决此问题:

mCurrentIntent.cancel();

Sorry, I don't yet have a good explanation as to why canceling the PendingIntent causes this issue. 抱歉,关于取消PendingIntent导致此问题的原因,我还没有很好的解释。

UPDATE: I also commented out the cancel in the MainActivity onStopUpdates() method: 更新:我还注释掉了MainActivity onStopUpdates()方法中的取消:

mDetectionRequester.getRequestPendingIntent().cancel();

Which is effectively doing the same thing as the first line above. 实际上,这与上述第一行在做相同的事情。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM