I've read many posts on the same topic and tried all the given solutions without getting the result I want. The program should start an intent with extras from a notification:
NotificationManager mNotificationManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
Intent notificationIntent = new Intent(context, myActivity.class);
notificationIntent.putExtra("someData", data);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
mNotificationManager.notify(ID, notification);
The problem is that when a new notification is shown, the extras added to the intent is the same as in the first notification. I've triend with differnt flags in both the intent and the pending intent, without result. What am I getting wrong? If i just launch the same activity (and the same extras) with a button, everything works as it's supposed to.
I don't know why I've had such problems with getting this to work. The combination of flags I used to get it to work properly was:
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent,
PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_ONE_SHOT);
I also removed all of the flags used when creating the notificationIntent
.
Try to add an attribute in AndroidManifest.xml file:
<activity ... android:launchMode="singleTop"/>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With