Android 捕获 crash

【Android 捕获 crash】一卷旌收千骑虏,万全身出百重围。这篇文章主要讲述Android 捕获 crash相关的知识,希望能为你提供帮助。

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());
}


























    推荐阅读