1
我試圖從服務發送通知,併成功執行該操作(通知確實在狀態欄上顯示)。 但是,點擊通知後,爲了觀看活動 - 我要回到手機主屏幕。另外,我在調試模式中注意到我沒有達到活動的「onCreate」方法。服務通知有效,但活動未啓動
這裏是我的一段代碼: 服務代碼:
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
int icon = R.drawable.notificationicon;
CharSequence tickerText = "Hello";
long when = System.currentTimeMillis();
Notification notification = new Notification(icon, tickerText, when);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0,
new Intent(this, NotificationsActivity.class), 0);
notification.setLatestEventInfo(this, "My notification","Hello World!", pendingIntent);
notificationManager.notify(1, notification);
活動代碼:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(dialogLayout);
}
AndroidManifest.xml中的NotificationActivity類是否定義良好? (你可以粘貼你的AndroidManifest?) –