1

나는 활동이있는 앱이 있는데, 대답은 A를 시작하는 알림 표시 줄에 넣습니다. 즉, 사용자가 알림을 선택하면 A 활동이 시작하라. 그러나 사용자가 뒤로 버튼을 누르면 이전 활동 (어쩌면 다른 앱) 대신에 시스템이 홈 화면으로 이동합니다. 어떻게하면 시스템이 A 액티비티를 끝내고 홈 스크린 대신 이전 액티비티로 돌아갈 수 있습니까?알림에서 홈 화면 대신 이전 앱으로 돌아 가기

알림 생성에 대한 나의 코드 :

resultIntent.setAction(Intent.ACTION_MAIN); 
resultIntent.addCategory(Intent.CATEGORY_LAUNCHER); 

및이 줄을 제거 :

resultIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 

Notification.Builder mBuilder = new Notification.Builder(this).setSmallIcon(R.drawable.icon).setContentText("title"); 
    Intent resultIntent = new Intent(this, ResultActivity.class); 
    resultIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
    PendingIntent pi = PendingIntent.getActivity(this, 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT); 
    mBuilder.setContentIntent(pi); 
    NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 
    mNotificationManager.notify(0, mBuilder.build()); 

답변

1

나는 다음 두 줄을 추가 답을 찾을 수가를 그러나 실제로 나는 왜 그런지 이해하지 못합니다. 누구든지 설명하거나 더 나은 대답을 주겠습니까?

+0

'FLAG_ACTIVITY_NEW_TASK'은 (는) 귀하의 활동이 루트에있는 새로운 백 스택을 생성합니다. 사용자가 과거를 뒤로하면 런처로 다시 전송됩니다. FLAG_ACTIVITY_NEW_TASK이 없으면 액티비티가 기존 백 스택의 맨 위에 추가됩니다. –