2011-11-04 127 views
0

我正在運行一項服務,它彈出有關獲取新任務的通知。如果我關閉了我的應用程序,它會在後臺運行並彈出通知。我想要做的是,當我點擊該通知時,打開應用程序。我可以這樣做嗎?怎麼樣 ?Android通知點擊

回答

3

您可以通過添加意圖您的通知做到這一點:

Intent notificationIntent = new Intent(context, YourAppActivity.class); 
    PendingIntent contentIntent = PendingIntent.getActivity(context, 0, 
      notificationIntent, 0); 
    notification.setLatestEventInfo(context, "headline", "body msg", contentIntent); 
    notifcationMgr.notify(id, notification); 

只是要開始練習更換YourAppActivity。

+0

感謝您的回覆。所以它會去點擊意圖? – user533844

+0

是的。如果您在下拉通知欄後單擊通知,它會啓動該意圖。 – Chris

+0

我需要添加FLAG_ACTIVITY_SINGLE_TOP嗎? – user533844