我使用以下代码将图标添加到通知状态,用户可以单击图标打开应用程序ui.SMSMain.class,并且两个ui.SMSMain.class应用程序将会如果用户点击两次图标,则会打开。 我希望应用程序只能打开一次,我该怎么办?如何防止应用程序打开重复
private static void ShowNotification() {
NotificationManager notificationManager = (NotificationManager) myContext.getSystemService(android.content.Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(R.drawable.smsforward,
myContext.getString(R.string.app_name),
System.currentTimeMillis());
notification.flags |= Notification.FLAG_ONGOING_EVENT;
notification.flags |= Notification.FLAG_NO_CLEAR;
CharSequence contentTitle =myContext.getString(R.string.NotificationTitle);
CharSequence contentText = myContext.getString(R.string.NotificationContent);
Intent notificationIntent = new Intent(myContext, ui.SMSMain.class);
PendingIntent contentItent = PendingIntent.getActivity(myContext, 0,
notificationIntent, 0);
notification.setLatestEventInfo(myContext, contentTitle, contentText,contentItent);
notificationManager.notify(NotificationID, notification);
}
您是否定义了目标活动的launch mide single_top? – Devrim