2014-01-25 55 views

回答

0

使用必須使用一些標誌,這可能會幫助ü

Intent notificationIntent = new Intent(context, MainActivity.class); 

    // set intent so it does not start a new activity 
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); 
    PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, 0); 
    notification.setLatestEventInfo(context, title, message, intent); 

    notification.flags |= Notification.FLAG_AUTO_CANCEL; 

    // Play default notification sound 
    notification.defaults |= Notification.DEFAULT_SOUND; 

    // Vibrate if vibrate is enabled 
    notification.defaults |= Notification.DEFAULT_VIBRATE; 

    notificationManager.notify(0, notification); 

還要檢查你的清單上從通知啓動活動

android:launchMode="singleTop" 

屬性。

+0

我用Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP ..但它是一樣的...打開的活動保持原樣... n新的意圖活動得到歡迎 – CoDe

1

當您創建Intent來啓動您的應用程序時,只需添加Intent.FLAG_ACTIVITY_CLEAR_TOP|Intent.FLAG_ACTIVITY_NEW_TASK即可。

注:但是,這隻有在你的根Activity仍然存在於任務(即工作:在你的任務在開始任何其他Activity當你沒有調用它的finish()

+0

謝謝...將給一個嘗試..但與它的應用程序正在玩多個場景:) – CoDe

+0

「多重場景」是什麼意思? –

+0

通知可以在應用程序的任何屏幕上展開,所以這個時候它將很難保持狀態...讓我們說,如果控制結束了某個屏幕,那麼它應該在那裏,如果它在屏幕B上..那麼它應該重定向到父像這樣。 – CoDe

相關問題