충돌 후 응용 프로그램을 다시 시작하고 싶습니다. 그래서 나는 Application 클래스에 충돌 핸들러를 만든 :충돌 후 응용 프로그램 시작
public final class MyApp extends Application {
private static Thread.UncaughtExceptionHandler mDefaultUEH;
private Thread.UncaughtExceptionHandler mCaughtExceptionHandler = new Thread.UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread thread, Throwable ex) {
Intent splashIntent = new Intent(getInstance().getActivity(), A1SplashScreen.class);
//splashIntent.addCategory(Intent.CATEGORY_LAUNCHER);
//splashIntent.setAction(Intent.ACTION_MAIN);
splashIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
splashIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
splashIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
int requestID = (int) System.currentTimeMillis();
PendingIntent pending = PendingIntent.getActivity(getInstance().getActivity(), requestID, splashIntent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_ONE_SHOT);
AlarmManager alarmManager = (AlarmManager) getInstance().getActivity().getSystemService(ALARM_SERVICE);
alarmManager.set(AlarmManager.RTC, System.currentTimeMillis(), pending);
mDefaultUEH.uncaughtException(thread, ex);
}
};
@Override
public void onCreate() {
super.onCreate();
Fabric.with(this, new Crashlytics());
mDefaultUEH = Thread.getDefaultUncaughtExceptionHandler();
Thread.setDefaultUncaughtExceptionHandler(mCaughtExceptionHandler);
}
}
A1SplashScreen이 응용 프로그램의 주요 활동이다, 그래서 충돌 후 그 활동을 시작하고 싶어. API 21 이상에서는 문제가 없습니다. 그러나 문제는 API 수준이 21보다 낮습니다. 응용 프로그램이 충돌 한 후 A1SplashScreen이 시작되지만 onCreate() 메서드가 호출되지 않습니다. 따라서 화면이 정지되고 아무 것도 표시되지 않습니다 (흰색 화면 만). 응답이 없으며 충돌하지 않습니다. 여기 스크린 샷입니다 :
이것은 실제로 신뢰할 수 없습니다. 이전 응용 프로그램을 다시 시작하기 전에 이전 프로세스가 올바르게 종료되도록 지연을 추가 할 수 있습니다. 5 초 또는 10 초 후에 경보가 울리면 도움이되는지 확인하십시오. –