0

Confusingly, the FusedLocationProviderApi stops sending intents.

A bit more detail: I have an Android service that builds a GoogleApiClient.

mClient = new GoogleApiClient.Builder(this)
        .addApi(LocationServices.API)
        .addApi(ActivityRecognition.API)
        .addConnectionCallbacks(this)
        .addOnConnectionFailedListener(this)
        .build();
mClient.connect();

Once connected, I request location updates using:

// Set up periodic location updates
Intent locationIntent = new Intent(this, LocationReceiver.class);
mLocationPendingIntent = PendingIntent.getBroadcast(
    this,
    0,
    locationIntent,
    PendingIntent.FLAG_UPDATE_CURRENT);
mFusedLocationProviderApi.requestLocationUpdates(
    mClient,
    mLocationRequest,
    mLocationPendingIntent);

And I request activities detected using:

// Set up activity recognition
Intent activityRecognizedIntent = new Intent(
    this,
    ActivityRecognizedReceiver.class);
mActivityRecognizedPendingIntent = PendingIntent.getBroadcast(
    this,
    0,
    activityRecognizedIntent,
    PendingIntent.FLAG_UPDATE_CURRENT);
mActivityRecognitionApi.requestActivityUpdates(
    mClient,
    ACTIVITY_DETECTION_INTERVAL,
    mActivityRecognizedPendingIntent);

When the service is killed by the OS, for example when I push a new version of the app to my phone, the ActivityRecognizedReceiver continues to receive updates! How can I stop that from happening? Why does the LocationReceiver stop receiving updates?

Keith Carter
  • 422
  • 1
  • 6
  • 18

2 Answers2

1

You need to remove location update request, for example :

LocationServices.FusedLocationApi.removeLocationUpdates(mGoogleApiClient,
                    getPendingIntent(context));
james
  • 1,967
  • 3
  • 21
  • 27
  • Thank you a lot, I tried stopping the IntentService itself, didn't know you have to actually unregister it in the GoogleApiClient – Big_Chair Sep 01 '15 at 18:14
0

The apps must be still running.unless you kill it with some app it wont stop. better try killing in the settings.

if you wanna stop it programmatically

in the onPause method stop receiving updates

and in onResume method once again start receiving updates.

Prasanth Perumal
  • 259
  • 1
  • 2
  • 4