private void initializeCrashHandlers() { // This crash handler can take care of anything, but you MUST close the process at the end if you are // not throwing an exception back to the default thread exception handler. To do this, we first get the // original thread handler and pass the exception to the previous thread handler (the only way this has // been found to work so far). final Thread.UncaughtExceptionHandler originalDefaultUncaughtExceptionHandler = Thread.getDefaultUncaughtExceptionHandler(); final Thread.UncaughtExceptionHandler scThreadExceptionHandler = new Thread.UncaughtExceptionHandler() { @Override public void uncaughtException(Thread thread, Throwable ex) { // take care of anything else here... for (Crashable crashable : mCrashables) { crashable.onApplicationCrash(AppContext.get(), thread, ex); } originalDefaultUncaughtExceptionHandler.uncaughtException(thread, ex); } }; // Set an uncaught exception handler to take care of cases where you want to do stuff before app crashes // This is also compatible with HockeyApp. Thread.setDefaultUncaughtExceptionHandler(scThreadExceptionHandler); ExceptionReportingProvider.initialize(GracefulExceptionHandler.getInstance(), new ExceptionReporter());}
时间: 2024-10-19 14:33:32