第二个通知不起作用
我尝试创建多个通知。如果点击通知,它将链接 到另一个活动。在执行以下代码后,它会创建两行通知。 但是当我单击通知的第一行时,它不起作用。 仅有第二部作品。
for (int i = 0; i < missionName.size(); i++) {
mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
final Notification notifyDetails = new Notification(R.drawable.icon,
"Mission Completed, Click Me!", System.currentTimeMillis());
notifyDetails.defaults |= Notification.DEFAULT_SOUND;
notifyDetails.defaults |= Notification.DEFAULT_VIBRATE;
Context context = getApplicationContext();
CharSequence contentTitle = missionName.get(i) + " is completed";
CharSequence contentText = "Please click to view the mission";
Intent notifyIntent = new Intent(getApplicationContext(),MissionMap.class);
notifyIntent.putExtra("missionName", missionName.get(i));
PendingIntent intent = PendingIntent.getActivity(ApplicationMenus.this,
0, notifyIntent, android.content.Intent.FLAG_ACTIVITY_NEW_TASK);
notifyDetails.setLatestEventInfo(context, contentTitle, contentText,
intent);
mNotificationManager.notify(i, notifyDetails);
}
所以,请帮我找出我的错误。太感谢了。
I try to create multiple notifications. If click on the notification, it will link
to another Activity. After following code, it's create two lines of notification.
But when I click to the first line of notification, it's not working.
Only second works.
for (int i = 0; i < missionName.size(); i++) {
mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
final Notification notifyDetails = new Notification(R.drawable.icon,
"Mission Completed, Click Me!", System.currentTimeMillis());
notifyDetails.defaults |= Notification.DEFAULT_SOUND;
notifyDetails.defaults |= Notification.DEFAULT_VIBRATE;
Context context = getApplicationContext();
CharSequence contentTitle = missionName.get(i) + " is completed";
CharSequence contentText = "Please click to view the mission";
Intent notifyIntent = new Intent(getApplicationContext(),MissionMap.class);
notifyIntent.putExtra("missionName", missionName.get(i));
PendingIntent intent = PendingIntent.getActivity(ApplicationMenus.this,
0, notifyIntent, android.content.Intent.FLAG_ACTIVITY_NEW_TASK);
notifyDetails.setLatestEventInfo(context, contentTitle, contentText,
intent);
mNotificationManager.notify(i, notifyDetails);
}
So, please help me to find my mistake. Thank you so much.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该使用不同的请求代码创建 PendingIntent。
更改为:
请
注意,我已将第二个参数更改为循环索引 (i),而不是 0。
如果您使用相同的参数,则不会创建意图,而是使用具有相同参数的先前意图。
这应该可以解决你的问题。
You should create the PendingIntent with different request codes.
Change this:
To this:
Note that I've changed the 2nd argument to your loop index (i) instead of 0.
Intents are not created if you use the same arguments but rather they use a previous intent with the same arguments.
This should solve your problem.