On Android 11 & 12 PendingIntents for notification launches will overwrite each other.
Repro Case
I have multiple push notifications with rewards attached
I open the game not from a push (Session 1)
While the game is open, I pull down the notification center and tap on a push. (Session 2)
I get the reward.
I pull down the notification center again and tap on a different push (Session 3)
I get told that I already claimed the reward, and the logs show that the session is being attributed to the same push as Session 2
The cause is that PendingIntent.getActivity is called with a requestCode of 0, instead of a random integer.
The fix is to replace that hard code of 0 as well as random integers with an atomic incrementing integer. Because the context will be different if the app is closed and then another notification comes in, the PendingIntent will still be unique.
On Android 11 & 12 PendingIntents for notification launches will overwrite each other.
Repro Case
The cause is that
PendingIntent.getActivity
is called with arequestCode
of 0, instead of a random integer.The fix is to replace that hard code of 0 as well as random integers with an atomic incrementing integer. Because the context will be different if the app is closed and then another notification comes in, the PendingIntent will still be unique.