2011-08-31 89 views
0

好吧, 我正在使用一項服務來收集&過程GPS數據的Android應用程序。該服務還會在狀態欄中創建通知。我無法弄清楚的是,當用戶點擊它時,如何讓通知打開主類。從我在網上找到的信息來看,不應該那麼難,但是我無法實現它。有沒有人有什麼建議在哪裏看?服務通知打開主要活動

+0

你有多遠? – njzk2

回答

2
Intent notificationIntent = new Intent(this, MyClass.class); 

這行代碼是從http://developer.android.com/guide/topics/ui/notifiers/notifications.html

只需將MyClass替換爲您的活動類 - 它將在您單擊通知時啓動。

+0

現在我感到很蠢。我已經在我的服務中的代碼,但有一個錯誤:(我有GPSService.class而不是Main.class。我使用的確切代碼是PendingIntent contentIntent = PendingIntent.getActivity(this,0,new Intent(this, Main.class),0); – smccloud