6

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

Community
  • 1
  • 1
Hrushikesh
  • 327
  • 3
  • 6

1 Answers1

6

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).
David Wasser
  • 93,459
  • 16
  • 209
  • 274
  • I have a RecyclerView list of cardviews. Each card has a future due date. Database stores a long for a 24-hour reminder Notification ("N."), a 20-minute reminder N. and a "Due now" N. for each card. I set up unique requestCodes as IDs using a distinct counter for each N. Example has 3 distinct cards. One 25 hours from now, one in 25 minutes and one in 5 minutes. The Notifications each fire but the "Due now" N. is deleting the "20-minute" N. and the 20-Min is deleting the 24-Hour N. as if I only have one card. I should be seeing the 3 distinct N. Any ideas on how to fix? – AJW Apr 05 '20 at 03:58
  • @AJW Please open a question for this. Hiding your question in a comment to my answer isn't the best way to get help. – David Wasser Apr 06 '20 at 08:17