2012-02-24 55 views
0

我有一個應用程序通過某種提醒來提醒用戶。這些提醒顯示爲通知。當用戶點擊任何這些通知時,它應該顯示關於該警報的附加信息。這基本上是通過調用具有特定參數的活動來完成的。單擊「通知」圖標時只顯示一次活動

這是我做的:

NotificationManager mNotificationManager = (NotificationManager) MyApplication.getContext().getSystemService(Context.NOTIFICATION_SERVICE);     
Notification notification = new Notification(R.drawable.reminder2, reminder.Title, System.currentTimeMillis()); 

Intent notificationIntent = null; 
notificationIntent = new Intent(MyApplication.getContext(), ReminderActivity.class); 
notificationIntent.putExtra("idnotification", reminder.ID); 


PendingIntent contentIntent = PendingIntent.getActivity(MyApplication.getContext(), reminder.ID, notificationIntent, 0); 

notification.defaults |= Notification.DEFAULT_SOUND; 
notification.defaults |= Notification.DEFAULT_VIBRATE; 
notification.defaults |= Notification.DEFAULT_LIGHTS; 
notification.defaults |= Notification.FLAG_INSISTENT; 


notification.setLatestEventInfo(MyApplication.getContext(), "Reminder", reminder.Title, contentIntent); 

mNotificationManager.notify(reminder.ID, notification); 

這似乎是工作,但問題是,如果我點擊一個通知一個以上的時間它會創建一個新的活動,而不是顯示一個已經可見。

我試着爲PendingIntent設置標誌,但沒有運氣。我試着用FLAG_CANCEL_CURRENT,FLAG_NO_CREATE,FLAG_ONE_SHOT,FLAG_UPDATE_CURRENT。唯一一個接近我需要的是FLAG_ONE_SHOT,但第二次點擊它並不顯示活動。

我還能試試嗎?我在這裏完全沒有想法。 謝謝

回答

1

Manifest設置launchModeActivitysingleTop。如果這不起作用,請嘗試singleInstance。我認爲其中之一可能更適合你。

如果這不起作用,嘗試用一些標誌搞亂了Intent

notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK)

我會嘗試以下標誌來看看有什麼效果,甚至使用超過一個:

FLAG_ACTIVITY_CLEAR_TOP 
FLAG_ACTIVITY_RESET_TASK_IF_NEEDED 
FLAG_ACTIVITY_CLEAR_TASK 
FLAG_ACTIVITY_NEW_TASK (in conjunction with others) 

你可以看到更多細節上的所有標誌here(下總結,Contstants ......然後所有以FLAG_ACTIVITY啓動標誌)。如果我的建議不起作用,我認爲您仍然可以在文檔中找到您的答案。

+0

感謝您的回覆。我仍然無法實現它,我對嘗試組合和組合以及在這個問題上花費時間感到厭倦。我想我會在用戶點擊時從狀態欄中刪除通知。問候 – LEM 2012-02-27 00:48:50