我目前在通知欄中顯示一條通知,當用戶單擊它時,它應該將它們帶到我的應用程序的根Activity。Android - 通知PendingIntent進入錯誤活動?
我用的android:finishOnTaskLaunch =「真」 &機器人:clearTaskOnLaunch在我的清單=「真」來實現這個當用戶按下從應用程序屏幕或主屏幕的應用程序圖標。用戶總是按照預期採取根本活動。
但是,當我從我的通知中使用以下代碼時,用戶將轉到他們所在的最後一個屏幕,而不是StartActivity的根活動。
有誰知道我在做什麼錯?
Intent notificationIntent = new Intent(this, StartActivity.class);
contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
notification.setLatestEventInfo(getApplicationContext(), getString(R.string.notification_app_name), notificationText, contentIntent);
mNotificationManager.notify(1, notification);
添加這些標誌有助於但它仍然沒有在重新啓動後的工作:
notificationIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
notificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
當我重新啓動我的應用程序設置服務運行的彈出通知,當我做到這一點,通知會恢復到舊的不需要的行爲。
解決:
加入這個標誌我通知的contentIntent解決問題 - Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED。
下面是一些優秀的信息在區域的鏈接Google dev group
能不能介紹一下你是如何使用的詳細說明:FLAG_ACTIVITY_RESET_TASK_IF_NEEDED。 –