勘误通知活动

时间:2012-12-22 10:09:52

标签: android

我有两个以闹钟管理器开头的通知。运行完美但我有一个问题:当第一个通知处于活动状态时(在通知栏中)如果我没有点击它,并且第二个通知开始,我会看到新的通知,但如果我点击新活动显示第一个通知。

String ns = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(ns);

int icon = R.drawable.ic_launcher;
CharSequence tickerText = not1[x];
long when = System.currentTimeMillis();

Notification notification = new Notification(icon, tickerText, when);

CharSequence contentTitle = "title";
CharSequence contentText = not1[x];

Intent notificationIntent = new Intent("org.gortcloud.perledisaggezza", null, context, Notify.class);
notificationIntent.putExtra("notify", not1[x]);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);

notification.defaults |= Notification.DEFAULT_SOUND;
notification.defaults |= Notification.DEFAULT_VIBRATE;
notification.defaults |= Notification.FLAG_AUTO_CANCEL;
notification.flags |= Notification.FLAG_AUTO_CANCEL | Notification.FLAG_SHOW_LIGHTS;

final int HELLO_ID = 1;

mNotificationManager.notify(HELLO_ID, notification);

1 个答案:

答案 0 :(得分:1)

尝试将以下标记添加到您的待处理意图PendingIntent.FLAG_CANCEL_CURRENT

像这样,

PendingIntent.getActivity(context,1, IntentObj, PendingIntent.FLAG_CANCEL_CURRENT);

在您的代码中,

PendingIntent contentIntent = PendingIntent.getActivity(context, 1, notificationIntent,PendingIntent.FLAG_CANCEL_CURRENT);