5
當我點擊狀態欄上的通知時,它會啓動一個活動,但行爲很奇怪。如果我的應用程序在前臺,並且點擊通知,則通知意圖會被觸發一次。如果我的應用程序在後臺,那麼通知意圖會被觸發兩次。如果我退出應用程序(即所有活動已經通過點擊後退按鈕彈出),那麼通知意圖會被觸發一次。任何人都可以解釋此行爲。的代碼片段如下:android通知兩次啓動相同的活動
_notification = new Notification(icon_id, "Ticker Text", System.currentTimeMillis());
_showActivityIntent = new Intent();
_showActivityIntent.setAction(MyActivityName);
_showActivityIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK + Intent.FLAG_ACTIVITY_NO_HISTORY);
_showActivityPendingIntent = PendingIntent.getActivity(context, 0, _showActivityIntent, 0);
_notification.setLatestEventInfo(context, "My title", "My text", _showActivityPendingIntent);
_notificationMgr.notify(notificationId, _notification);
我會試試看,但你能解釋爲什麼同一個活動正在啓動兩次? – pankajagarwal 2010-12-02 11:34:55