android pending intent notification problem
The way I solved that problem was by assigning a unique requestCode when you get the PendingIntent:
PendingIntent.getActivity(context, requestCode, showIntent, 0);
By doing so you are registering with the system different/unique intent instances. Tip: A good way of making the requestCode unique would be by passing to it the current system time.
int requestID = (int) System.currentTimeMillis();
The problem is that when I create more than one alarm then the activity launched from the notification gets the same extras as the first one.
Correct.
How can I make it to launch the correct intents?
That depends on whether you have two alarms that will be registered at once, or not.
If not, you can use FLAG_ONE_SHOT
or one of the other PendingIntent
flags to have your second PendingIntent
use the newer extras.
If, however, you will have two alarms registered at once, with different Intent
extras, you will need to make the two Intents
be more materially different, such that filterEquals()
returns false
when comparing the two. For example, you could call setData()
or setAction()
and provide different values for each Intent
.