Possible Duplicate:
Android: how to cancel a request of Location update with intent?
I am trying to disable a pending intent(broadcast) which I have previously created in a different activity but I can't get it to work. I've read that I should recreate the intent(with the same extras and everything), pass it as a parameter so that I can instantiate the pendingIntent and then pass the pendingIntent as a parameter to the location managers removeUpdates method.
In other words:
Bundle extra = new Bundle();
extra.putString("name", extras.getString("poiName")); //create same extras
extra.putInt("id", extras.getInt("rowId")); //create same extras
Intent intent = new Intent(PROX_ALERT_INTENT);
intent.putExtra(PROX_ALERT_INTENT, extra); //put same extras in the intent
PendingIntent proximityIntent = PendingIntent.getBroadcast(this.getApplicationContext(),extras.getInt("rowId") , intent, PendingIntent.FLAG_UPDATE_CURRENT); //pass in the intent
LocationManager locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
locationManager.removeUpdates(proximityIntent); //remove pendingIntent
That didn't work so I thought that it might have to do with the intent that im passing in being a new object and not the same with the one used in order to create the pending intent.
So I tried removing the pendingIntent right after I create it but that didnt work either:
Bundle extras = new Bundle();
extras.putString("name", poiName);
extras.putInt("id", requestCode);
Intent intent = new Intent(PROX_ALERT_INTENT);
intent.putExtra(PROX_ALERT_INTENT, extras);
PendingIntent proximityIntent = PendingIntent.getBroadcast(this.getApplicationContext(), requestCode , intent, PendingIntent.FLAG_CANCEL_CURRENT);
locationManager.addProximityAlert(
latitude, // the latitude of the central point of the alert region
longitude, // the longitude of the central point of the alert region
POINT_RADIUS, // the radius of the central point of the alert region, in meters
PROX_ALERT_EXPIRATION, // time for this proximity alert, in milliseconds, or -1 to indicate no expiration
proximityIntent // will be used to generate an Intent to fire when entry to or exit from the alert region is detected
);
locationManager.removeUpdates(proximityIntent);
Can you please help me with that??? Its been bugging be since wednesday...wish i had more reputation to put a boundy on this one...
Thanks
mike
Resolved it by recreating the intent and then calling .cancel() on the pending intent...