我在android中的通知有问题,每当我每次点击通知时,我都必须再次调用相同的活动,但据我认为新活动被调用但前一个也在后端运行,由于我的代码一次又一次地运行(因为多个实例)
请帮助我每次单击通知时如何解决或关闭多个实例。
代码
public void notificationforChat(CharSequence message,String toJid, int notificationID) {
int notificationCount = 1;
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);
int icon = R.drawable.ic_launcher;
CharSequence tickerText = message;
long when = System.currentTimeMillis();
Notification notification = new Notification(icon, tickerText, when);
//notification.number = notificationCount++;
Context context = getApplicationContext();
CharSequence contentTitle = "Chat";
CharSequence contentText = message;
Intent notificationIntentforChat = new Intent(this, UserChatActivity.class);
notificationIntentforChat.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
notificationIntentforChat.putExtra("userNameVal", toJid);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
notificationIntentforChat, PendingIntent.FLAG_UPDATE_CURRENT);
notification.setLatestEventInfo(context, contentTitle, contentText,
contentIntent);
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notification.defaults = Notification.DEFAULT_ALL;
mNotificationManager.notify(notificationID, notification);
}
谢谢