我使用以下代碼將圖標添加到通知狀態,用戶可以單擊圖標打開應用程序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