1
我陷入了一個問題。 假設現在有一個活動A ,用戶按Home鍵,並將A置於後臺。 現在,在留在後臺一段時間後,它會生成一個通知。 點擊該通知後,它將返回與後臺完全相同的活動。 就像按住home鍵後,如果用戶通過點擊圖標或從最近啓動的歷史記錄中再次啓動應用程序,那麼android會重新打開上次的活動。 在這裏,我不想檢測哪個是最後一個活動。我的活動是固定的,我只想通過點擊通知恢復到以前的狀態。 這可能嗎?怎麼做 ? 這裏是我的通知代碼,從前臺帶回活動
private void generateNotification(Context context, String message, String data) {
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(R.drawable.notification, message, System.currentTimeMillis());
Intent notificationIntent = new Intent(context, MenuActivity.class);
//notificationIntent.setFlags(Notification.FLAG_ONGOING_EVENT | Notification.FLAG_NO_CLEAR);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY);
Bundle bundle = new Bundle();
bundle.putString("data",data);
notificationIntent.putExtras(bundle);
//Constants.NOTIFICATION_ID++;
notification.setLatestEventInfo(context, context.getString(R.string.app_name), message, PendingIntent.getActivity(context, 0, notificationIntent, Notification.FLAG_ONGOING_EVENT | Notification.FLAG_NO_CLEAR));
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notificationManager.notify(Constants.NOTIFICATION_ID, notification);
}