마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

startActivity 로 새 액티비티를 띄우면 부모 액티비티가 onDestroy 됩니다;;

0 추천
A -> B 를 호출하면 A 가 onStop 에 머물러 있지않고 onDestroy 해서 사라집니다;; 혹시 경험하신 분 있으신가요?

A 는 아래처럼 띄워져있고

Intent i = new Intent(context, A.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_CLEAR_TOP);
context.startActivity(i);

B 는 아래처럼 호출됩니다.

Intent i = new Intent(this, B.class);
startActivity(i);

 

휴대폰에 있는 개발자 옵션 문제는 아니구요.. 구글링해도 해결하기가 어렵네요..
익명사용자 님이 2016년 10월 18일 질문

1개의 답변

0 추천

개발자 문서에서 퍼왔습니다.

 

FLAG_ACTIVITY_NEW_TASK

If set, this activity will become the start of a new task on this history stack.

FLAG_ACTIVITY_CLEAR_TOP

If set, and the activity being launched is already running in the current task, then instead of launching a new instance of that activity, all of the other activities on top of it will be closed and this Intent will be delivered to the (now on top) old activity as a new Intent.

제 생각으로는 두가지 옵션이 결합되어서 기존 백스택에 있는 액티비티들을 다 닫고 있는 것 같습니다. 해당 옵션을 주석처리하고 실행해보시면 차이를 확연히 알 수 있겠네요.

spark (227,830 포인트) 님이 2016년 10월 18일 답변
A 는 리시버에서 띄는거라 FLAG_ACTIVITY_NEW_TASK 옵션을 없앨수 없고 FLAG_ACTIVITY_CLEAR_TOP 를 제외하고 실행해 봤으나 결과는 같네요..
미쳤나 봅니다.. 매니페스트에 해당 액티비티를 android:noHistory="true" 해놓고서는;;; 답글 달아주셔서 감사해요
...