0

I have a JSON message being sent to a listening service in my first Android app (read: pelase be gentle!) that is mapped to an object that implements Parcelable. The deserialized object is used to display a notification, with an intent that is meant to launch another activity displaying the full data in a layout.

Using the deserialized object I'm able to display the information in the notification without issue. The code in the notification to launch the secondary activity:

Intent intent = new Intent(this, SecondaryActivity.class);
intent.putExtra("objData", myObj);

PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, 0);

NotificationCompat.Builder mBuilder =
            new NotificationCompat.Builder(this)
                    .setContentTitle(myObj.getTitle())
                    .setStyle(new NotificationCompat.BigTextStyle()
                            .bigText(myObj.getAbstract()))
                    .setContentText(myObj.getAbstract());

mBuilder.setContentIntent(contentIntent);
mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());

In the SecondaryActivity I unwrap the parcel like so:

MyObject myObj = getIntent().getParcelableExtra("objData");

and use its data to fill in areas of the layout.

This works great on the first notification. On subsequent notifications, the notification looks correct but the parcelable data sent to SecondaryActivity is not updated (the content appears to the same as the first notification).

I'm assuming I'm missing something obvious that is preventing the parcelable object from being updated. Can you help?

k3davis
  • 985
  • 12
  • 29
  • could you post the code of the SecondaryActivity? Also does the problem occur only when you have the SecondaryActivity already open and you click the a new notification? or is does it also happen when you click the notification the SecondaryActivity opens you close it a new notification is show with new data and you click it which opens the old SecondaryActivity still with the old data? – Aegis Dec 21 '15 at 16:19

1 Answers1

2

When creating the pending intent you could try adding the flag FLAG_CANCEL_CURRENT or FLAG_UPDATE_CURRENT

PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, 0);

PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
Aegis
  • 5,761
  • 2
  • 33
  • 42