Question

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

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.

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.

P.S. I'm using Google Play services rev 16. along with a Samsung galaxy s2 android version 4.1.2

Was it helpful?

Solution

I noticed this same problem running the sample code on my 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:

mCurrentIntent.cancel();

Sorry, I don't yet have a good explanation as to why canceling the PendingIntent causes this issue.

UPDATE: I also commented out the cancel in the MainActivity onStopUpdates() method:

mDetectionRequester.getRequestPendingIntent().cancel();

Which is effectively doing the same thing as the first line above.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top