I want to create several notifications that launches an activity (or refresh it) to display a product description.
Notification notification = new Notification(R.drawable.applicationicon,
Resources.getString("NewSaleNotification", context),
System.currentTimeMillis());
// Hide the notification after its selected
notification.flags |= Notification.FLAG_AUTO_CANCEL;
Intent intent = new Intent(context, MainApplication.class);
intent.putExtra("saleid", saleid);
// to be sure the activity won't be restarted
intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent,
PendingIntent.FLAG_UPDATE_CURRENT);
notification.setLatestEventInfo(context, SaleTitle, SaleMessage, pendingIntent);
notificationManager.notify(saleid, notification);
When I create the PendingIntent, I have 4 choices : FLAG_CANCEL_CURRENT, FLAG_NO_CREATE, FLAG_ONE_SHOT and FLAG_UPDATE_CURRENT.
The definition of the last one (http://developer.android.com/reference/android/app/PendingIntent.html#FLAG_UPDATE_CURRENT) is what I want to do but it doesn't work as it should. If I create 2 notifications, they both have the same 'saleid' extra which is the latest one. How can I make more than one notification with different 'saleid' extra?
Yes, it does.
This is precisely what the documentation says is supposed to happen.
Option #1: Put a different action string in each of your
Intents
. This will make them different (from the standpoint offilterEquals()
) and give them separatePendingIntents
. However, since you are specifying the component in theIntent
(MainApplication.class
), the action will not affect how theIntent
is routed.Option #2: Use a different
requestCode
(2nd parameter) on yourgetActivity()
calls. While this is documented as "currently not used", it does result in differentPendingIntent
objects being returned. However, since this behavior is undocumented, it may change in the future.