0

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

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);
4

1 回答 1

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);
于 2012-12-22T10:24:16.467 回答