Android Status Bar Notifications - Intent getting the old extras on the second time?

You need to set up a clean flag to PendingIntent.

Up vote 1 down vote favorite share g+ share fb share tw.

When I create a notification that is sent through C2DM and received in my app I want to pass some of the data that came with the push notification from C2DM in the intent extras. This works fine the first time I open my notification. Then the data is received with onNewIntent or in onCreate depending on the state of the activity.

But if I send a second push notification through C2DM it is received correctly with the new data but when getting the extras from the intent I still get the data from the previous message. The title and the data I want to see is shown correctly in the notification. So something must be wrong the my intent.

This happens if the activity is running and if it isn't. To create the notification I do the following: NotificationManager notificationManager = (NotificationManager) context. GetSystemService(Context.

NOTIFICATION_SERVICE); Notification notification = new Notification(R.drawable. Ic_stat_notify_push, "Message received", System. CurrentTimeMillis()); notification.

Flags |= Notification. FLAG_AUTO_CANCEL; notification. Sound = RingtoneManager.

GetDefaultUri(RingtoneManager. TYPE_NOTIFICATION); notification. Defaults |= Notification.

DEFAULT_LIGHTS; Intent intent = new Intent(context, DesktopApp. Class); intent. SetAction("android.intent.action.

MAIN"); intent. AddCategory("android.intent.category. LAUNCHER"); intent.

SetFlags(Intent. FLAG_ACTIVITY_CLEAR_TOP | Intent. FLAG_ACTIVITY_SINGLE_TOP); intent.

PutExtra("msg_id", msg_id); intent. PutExtra("title", title); PendingIntent pendingIntent = PendingIntent. GetActivity(context, 0, intent, 0); notification.

SetLatestEventInfo(context, "New message", title + String. ValueOf(msg_id), pendingIntent); notificationManager. Notify(0, notification); To then read the intents: public void onCreate(Bundle savedInstanceState) { super.

OnCreate(savedInstanceState); setContentView(R.layout. Main); Intent myIntent = getIntent(); // this is just for example purpose int I = myIntent. GetIntExtra("msg_id", -1); if (i!

= -1) Toast. MakeText(this, "Got message! " + String.

ValueOf(i), Toast. LENGTH_LONG).show(); } @Override public void onNewIntent(Intent intent){ super. OnNewIntent(intent); Bundle extras = intent.getExtras(); if (extras!

= null) { int I = extras. GetInt("msg_id", -1); if (i! = -1) Toast.

MakeText(this, "Got message! " + String. ValueOf(i), Toast.

LENGTH_LONG).show(); } } Any suggestions? Android android-intent notifications push-notification link|improve this question asked Feb 9 at 9:49just_user1147 93% accept rate.

You need to set up a clean flag to PendingIntent: PendingIntent pintent = PendingIntent. GetActivity(context,0,intent,PendingIntent. FLAG_CANCEL_CURRENT); Have a look at this post that gives a longer explanation.

Great explanation, thanks! – just_user Feb 9 at 10:03.

USE THIS PendingIntent pintent = PendingIntent. GetActivity(context,UNIQUE ID,intent,PendingIntent. FLAG_UPDATE_CURRENT).

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions