tags:

views:

76

answers:

1

I registered a PendingIntent to requestLocationUpdates(provider, minTime, minDistance, PendingIntent). But when my broadcast receiver receives this intend, how do I remove this request with removeUpdates(PendingIntent)? The receiver doesn't hold a reference to the original PendingIntent.

+1  A: 

You create an equivalent PendingIntent. In other words, create an Intent that matches the one you used originally (though you can skip any extras), wrap that in the same sort of PendingIntent that you used originally, and use that PendingIntent in the removeUpdates() call.

CommonsWare
Thank you. In my receiver's onReceive(context, intent) method, I called PendingIntent origPendingIntent = PendingIntent.getBroadcast(context,0, intent, PendingIntent.FLAG_UPDATE_CURRENT) right away with the same intent passed in to remove the updates. But somehow, it didn't remove the update request. I can still receive the updates.
wei
@wei: Try getting rid of `FLAG_UPDATE_CURRENT` and see if that helps.
CommonsWare
Thanks a lot! It works now. It turns out that I have to create a new Intent instance(not sure why, tho)and set the flag to 0 to make it work.
wei