2

Hi I am developing android application and in that I am using activity recognition. I download Google's sample application for activity recognition. It working properly without any error. But my main problem is in following sequence :

I install that application and I start activity recognition. Without stopping that service I uninstall hat application. again I install same application. My Application start listening for activity recognition without my asking me.

So I want to know how it actually works. Why it is continue that service after uninstalling my application. Next time it start listening for activity results.

Am i missing something. Or doing something wrong ?

Need Help thank you.

TheCodeArtist
  • 21,479
  • 4
  • 69
  • 130
nilkash
  • 7,408
  • 32
  • 99
  • 176

2 Answers2

1

It sound like you aren't stopping listening for the recognition intents.

To stop listening for these you need to make sure you are calling:

yourActivityRecognitionClient.removeActivityUpdates(youtActivityRecognitionIntent);

Put the above in the onDestroy() function and it should stop listening for intents on stopping the service.

  • I want to continue in background continuously. So I don't want to stop it. But how it continue if I uninstall again install my application. I have to stop it either when user uninstall my application or after install installation I have to check whether it is running or not and then stop that time... So is it proper behavior of activity detection. Why it is start listening after re-installing application without calling start listen .... Need Help thank you for replay... – nilkash Jul 17 '13 at 11:35
  • The way I understand it is that the activity recognition, once registered for updates, will continue to look for updates until its unregistered, even if your app is not running. Uninstalling the app will remove your code so it shouldn't trigger anything listening for the activity updates but unless it's been stopped I think your client will still be sitting in memory trying to get updates. – metalmonkeysoftware Jul 17 '13 at 12:15
  • OH So how to resolve this? Is there any way to do this. at least any way to check whether it running or not at first load. – nilkash Jul 17 '13 at 12:22
  • Record a boolean in your service that activity recognition is running and on app launch / installation start the service (which will trigger an onStartCommand and in that do your checks against whether the activity recognition is running or not and then take what other actions your need. – metalmonkeysoftware Jul 17 '13 at 12:56
1

you should also cancel the pendingIntent, using pendingIntent.cancel()

enshrentko
  • 29
  • 5