app 재실행 하기

Android 2013. 10. 24. 10:19

app 운용 중 app에서 문제가 감지되어 재실행이 필요할 때, 특히 종료 시 System.exit(?) 가 문제가 많았다.


System.exit 의 문제는 app 종료 시 Activity lifecycle(onPause onStop onDestroy)에 대한 보장이 없다는 것,


결국 아래와 같이 고치고 나니 굉장히 안정적이게 됨.


PendingIntent i = PendingIntent.getActivity(getApplicationContext(), 0, new Intent(getIntent()), getIntent().getFlags());

AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);

am.set(AlarmManager.RTC, System.currentTimeMillis() + 5000, i);

//System.exit(2)

moveTaskToBack(true); 

finish();

android.os.Process.killProcess(android.os.Process.myPid());




<추가>


시스템 앱의 경우 무슨 짓을 해도 다시 살아나더이다..

일반적인 경우에는 문제가 없는데, 같이 실행된 서비스가 프로세스에는 안보이고 (exported="false" → :remote 로 안뜸)

종료할 때 서로 연결되어 있던 서비스가 깔끔하게 unbind 되지 않음.

이 상태로 앱이 재시작 되면 먼저 있던 서비스와 bind가 안되는 경우가 가끔 나타남(타겟 특성일 수도 있음)

결국 재부팅으로 해결.. 흑..

'Android' 카테고리의 다른 글

현재 파티션 정보 보기  (0) 2016.05.18
빨간 테두리 나오는 현상  (0) 2013.10.23
Ethernet 사용을 위한 Kernel 설정  (0) 2013.08.07
Android 빌드 시스템 (Make file 관련)  (0) 2013.08.05
System app 구분  (0) 2013.08.05
Posted by 독뽀
,