4

I've been playing around with User's activity recognition and the Fused location provider and noticed that even after I uninstalled the sample app, activity recognition requests / location requests are still being fired as I'm seeing the following every couple of seconds :

05-20 23:20:22.569: W/ActivityManager(389): Unable to start service Intent { cmp=com.example.android.activityrecognition/.ActivityRecognitionIntentService (has extras) } U=0: not found

The exception obviously coming from the fact that my service is gone (app uninstalled).

I'm seeing the same thing with the location provider.

As a consequence, if a pending intent was used like this

Intent intent = new Intent(Constants.INTENT_ACTION_LOCATION_UPDATED);
PendingIntent pendingIntent = PendingIntent.getService(BasicMapActivity.this, LOCATION_INTENT_CODE, intent, 0);
LocationRequest locationRequest = LocationRequest.create().setInterval(5000).setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
locationClient.requestLocationUpdates(locationRequest, pendingIntent);

This could leave the GPS polling for a location all the time in the event the app is uninstalled or the app has crashed and no proper "user-cleanup" took place.

Is this normal behavior ? I would imagine some cleanup on PendingIntents would be done when the app is removed .

Is this related to the fact that these request are flowing through the Google Play Services process ?

How should we deal with this ?

EDIT : Posted an issue in the Android tracker but was told this is not the correct place for reporting issues with Google Apps. Posted it on the Google Mobile Help Forum

ddewaele
  • 22,363
  • 10
  • 69
  • 82
  • If what you're reporting is correct, that's a bug in Play Services AFAICT. There's no way for our apps to do anything at uninstall time, and so it is up to these services to clean this stuff up, such as by catching exceptions raised when they `send()` the `PendingIntent` and unregistering the failing request. I haven't started playing with this new stuff yet, but I'll try to reproduce your findings when I do. If you can craft a reproducible test case (probably not hard), file an issue about it, presumably at http://b.android.com (unless Play Services has their own tracker somewhere...). – CommonsWare May 20 '13 at 23:17
  • The Google sample apps do proper cleanup in onStop(). However, this means that they cannot do background processing right ? (When the user exits the app the location / activityrecognition client is stopped and disconnected). In my sample app I also want to do updates when the Activity is exited. Are you saying that even in that case Google Play Services should manage the cleanup ? – ddewaele May 20 '13 at 23:31
  • 1
    "Are you saying that even in that case Google Play Services should manage the cleanup ?" -- yes, particularly for things like geofencing. The demo they showed of that (Zillow) was specifically designed to let the app know about the user entering a geofenced area without that app necessarily already running. Hence, if they want to support that scenario, they have to clean up outstanding requests at uninstall time. – CommonsWare May 20 '13 at 23:33
  • Created bug report : https://code.google.com/p/android/issues/detail?can=2&start=0&num=100&q=&colspec=ID%20Type%20Status%20Owner%20Summary%20Stars&groupby=&sort=&id=55616. Added a github project + APK. Hope it's clear. – ddewaele May 20 '13 at 23:46
  • Awesome! I'm not in position to play with this stuff this week, but I will as soon as I get a chance. Of course, even more awesome would be if this problem did not exist in the first place... – CommonsWare May 21 '13 at 04:09
  • I get the same basic behavior, in that the GPS icon remains lit. However, I don't get the "Unable to start service" messages. – CommonsWare Jun 07 '13 at 20:00
  • @CommonsWare What Android version where you running on ? emulator or real device ? Anyways ... seems strange that the GPS icon would remain lit. Would be interested in finding a battery-efficient way of retrieving locations in the background using a regular interval. – ddewaele Jun 08 '13 at 18:49
  • Real device (Nexus 4 or Galaxy Nexus, I forget which). – CommonsWare Jun 08 '13 at 18:54

0 Answers0