Hrushikesh
Hrushikesh

Reputation: 327

Has requestCode in PendingIntent always been supported?

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"?

Upvotes: 6

Views: 2038

Answers (1)

David Wasser
David Wasser

Reputation: 95646

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 PendingIntents is robust and supported. The documentation even says so:

  • If you truly need multiple distinct 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).

Upvotes: 6

Related Questions