11

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.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Emil
  • 1,414
  • 1
  • 12
  • 14
  • possible duplicate of [Android keeps caching my intents Extras, how to declare a pending intent that keeps fresh extras?](http://stackoverflow.com/questions/3140072/android-keeps-caching-my-intents-extras-how-to-declare-a-pending-intent-that-kee) – Pentium10 Jul 05 '10 at 13:18
  • 1
    Yes, the thing is, i read that post, and a couple more, but none of them worked for me. However, in some way, i managed to solve it, and will post my solution here soon. – Emil Jul 05 '10 at 14:34

3 Answers3

10

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.

Emil
  • 1,414
  • 1
  • 12
  • 14
5

Try to add an attribute in AndroidManifest.xml file:

<activity ... android:launchMode="singleTop"/>
Vaha
  • 131
  • 2
  • 2
0

Try to set request code for each PendingIntent and it will work

PendingIntent pendingIntent = PendingIntent.getActivity(this, RandomInt, intent,
                PendingIntent.FLAG_ONE_SHOT);
Aditi Rawat
  • 784
  • 1
  • 12
  • 15