I am in a case where my Watch application has updated data and will display these data in multiple pages.
According to this answer: https://stackoverflow.com/a/30133449/327402 , I created a displayIntent for each one of my page.
List extras = new ArrayList();
//This is a loop to create every individual Notification
for (Route aRoute : myRoutes) {
Intent viewIntent = new Intent(getApplicationContext(), MainActivity.class);
String toSend = aRoute.detail;
Log.d("CVE",toSend);
viewIntent.putExtra("KEY", toSend);
PendingIntent displayendingIntent = PendingIntent.getActivity(getApplicationContext(), 0,viewIntent, PendingIntent.FLAG_UPDATE_CURRENT);
Notification aNotif = new NotificationCompat.Builder(getApplicationContext())
.setLargeIcon(bitmap)
.extend(new NotificationCompat.WearableExtender()
.setDisplayIntent(displayendingIntent)
.setCustomSizePreset(Notification.WearableExtender.SIZE_MEDIUM))
.setSmallIcon(R.mipmap.ic_launcher)
.build();
extras.add(aNotif);
}
//This is "main" notification.
NotificationCompat.Builder builder1 = new NotificationCompat.Builder(this)
.setContentTitle(title)
.setContentText(desc)
.setSmallIcon(R.mipmap.ic_launcher);
Notification notification = builder1
.extend(new NotificationCompat.WearableExtender()
.addPages(extras))
.build();
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
notificationManager.notify(0, notification);
Till here, it looks OK, but when I read what happens on every notification, I realize that the data is the same.
This is my simplified Activity:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mTextView = (TextView) findViewById(R.id.text_view);
mTextView.setText("Value: "+getIntent().getStringExtra("KEY"));
}
The problem is that the Log (see line 6 of the first part part of the code) displays correctly:
"Text 1" "Text 2" "Text 3"
, but in reality, "Text 3" is displayed in every Notification!
How should I fix this?