I'm trying to distinguish between different instances of PendingIntent by having separate requestCode for each use-case as suggested by this earlier question.
Is this a robust solution? Has requestCode always been supported even though the javadocs still say that it is "currently not used"?
requestCode is used to retrieve the same pending intent instance later on (for cancelling, etc).
FLAG_ONE_SHOT. Flag indicating that this PendingIntent can be used only once. int. FLAG_UPDATE_CURRENT. Flag indicating that if the described PendingIntent already exists, then keep it but replace its extra data with what is in this new Intent.
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.
Android PendingIntent In other words, PendingIntent lets us pass a future Intent to another application and allow that application to execute that Intent as if it had the same permissions as our application, whether or not our application is still around when the Intent is eventually invoked.
Yes. The requestCode
has always been there. It isn't currently used by the Android framework to do anything other than as part of the test for PendingIntent
matching. Using requestCode
to determine different PendingIntent
s is robust and supported. The documentation even says so:
PendingIntent
objects active at the same time (such as to use as two notifications that are both shown at the same time), then you will need to ensure there is something that is different about them to associate them with different PendingIntents. This may be any of the Intent
attributes considered by Intent.filterEquals
, or different request code integers supplied to getActivity(Context, int, Intent, int)
, getActivities(Context, int, Intent[], int)
, getBroadcast(Context, int, Intent, int)
, or getService(Context, int, Intent, int)
.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With