我在我的收藏应用已更新的数据,并显示在多个页面中这些数据的情况。
根据这样的回答: https://stackoverflow.com/a/30133449/327402 ,我创造了我的网页中的每一个displayIntent。
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);
到这里,它看起来不错,但是当我看到在每一个通知会发生什么,我知道的数据是一样的。
这是我简单的活动:
@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"));
}
的问题是,登录(见代码的第一部分部分的第6行)正确显示:
“文本1”,“文本2”,“文本3”
,但在现实中,“文本3”显示在每一个通知!
我应该怎样解决这个问题?