我正在尝试在通知栏中显示元素列表。现在我有一组通知,但我单击的每个通知都将我带到相同的活动,即我无法存储通知的位置。
这是我的代码
if (list != null && !list.isEmpty()) {
for (int i = 0; i < list.size(); i++) {
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
context)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle(
"Coupon Received From "
+ list.get(i).merchantName)
.setContentText(
"Coupon Value : "
+ list.get(i).couponValue)
.setAutoCancel(true)
.setTicker("Coupon alert message from Kluebook")
.setVibrate(new long[] { 100, 250, 100, 250 });
Intent resultIntent = new Intent(context,
CouponDetailActivity.class);
resultIntent.putExtra("couponid",
list.get(i).couponid);
resultIntent.putExtra("position", list.get(i).i);
resultIntent.putExtra("branchid",
list.get(i).issuedBranchid);
PendingIntent resultPendingIntent = PendingIntent.getActivity(
context, 0, resultIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
mBuilder.setContentIntent(resultPendingIntent);
NotificationManager mNotifyMgr = (NotificationManager) context
.getSystemService(context.NOTIFICATION_SERVICE);
mNotifyMgr.notify(i + 1, mBuilder.build());
}
} else {
System.out.println("+++++++++++ IT IS EMPTY +++++++++++++++ list");
}
}
如果我在通知栏中收到 5 个通知,则每个通知都会将我带到第一个通知活动。