Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why the PendingIntent doesn't send back my custom Extras setup for the Intent?

This questions somehow relates to the question when I was looking to get the extras back in startActivityForResult but now I face another challenge.

I have subscribed to receive ProximityAlerts and I have explicitly constructed the Intent to include some Extras. But when I got the service the extras are not there.

After the answers here is the working code:

Intent intent = new Intent(this, PlacesProximityHandlerService.class); intent.setAction("PlacesProximityHandlerService"); intent.putExtra("lat", objPlace.getLat()); intent.putExtra("lon", objPlace.getLon()); intent.putExtra("error_m", objPlace.getError()+ALERT_RANGE_IN_METERS); PendingIntent sender=PendingIntent.getService(this, 0, intent, 0); LocationUtils.addProximity(this, objPlace.getLat(), objPlace.getLon(),objPlace.getError()+ALERT_RANGE_IN_METERS, -1, sender); 

The documentation says param PendingIntent to be sent for each location update

like image 623
Pentium10 Avatar asked Jun 27 '10 16:06

Pentium10


People also ask

What is the difference between intent and PendingIntent?

In conclusion, the general and main difference between Intent and PendingIntent is that by using the first, you want to start / launch / execute something NOW, while by using the second entity you want to execute that something in the future.

What is requestCode in PendingIntent?

1- requestCode is used to get the same pending intent later on (for cancelling etc) 2- Yes, they will get override as long as your specify the same Receiver to your Intent that you specify on your PendingIntent.

What is the use of pending intent?

A PendingIntent itself is simply a reference to a token maintained by the system describing the original data used to retrieve it. This means that, even if its owning application's process is killed, the PendingIntent itself will remain usable from other processes that have been given it.


1 Answers

For some unspecified reason, extras will be delivered only if you've set some action, for example setAction("foo"). What CommonsWare refers to applies only when obtaining PendingIntent instances, if you haven't set FLAG_ONE_SHOT. That can be fixed by the requestCode argument in PendingIntent.get... factory methods. Although documentation says it's currently not used, it actually takes into count when distinguishing PendingIntents.

In your case, you don't need to set anything else than some dummy action string. LocationManagerService reuses the PendingIntent you have subscribed for proximity alerts, and only adds a flag if phone has entered or exited the alarm range.

like image 177
ognian Avatar answered Sep 17 '22 20:09

ognian