Android 如果我使用 ACRA,则不会调用 UncaughtExceptionHandler
Android UncaughtExceptionHandler not called if I use ACRA
它适用于 Android 5.0,但不适用于 Jellybean 设备。
@ReportsCrashes(
formKey = "", // This is required for backward compatibility but not used
formUri = "dummyurl",
reportType = org.acra.sender.HttpSender.Type.JSON,
httpMethod = org.acra.sender.HttpSender.Method.PUT,
formUriBasicAuthLogin="adminTest",
formUriBasicAuthPassword="adminTest",
mode = ReportingInteractionMode.TOAST,
resToastText = R.string.crash_toast_text)
public class Application extends Application {
@Override
public void onCreate() {
super.onCreate();
init();
ACRA.init(this);
Thread.setDefaultUncaughtExceptionHandler(sUncaughtExceptionHandler);
}
private UncaughtExceptionHandler sUncaughtExceptionHandler = new UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread thread, Throwable ex) {
Log.i(LogTag, "uncaughtException: ");
dummyMethod();
Thread.getDefaultUncaughtExceptionHandler().uncaughtException(
thread, ex);
}
};
}
ACRA 设置自己的 UncaughtExceptioHandler 执行错误报告,然后委托给之前存在的任何 UncaughtExceptionHandler。
因此,如果您希望在 ACRA 完成错误报告后调用 UncaughtExceptionHandler,则需要在 调用 调用 ACRA.init(this);
[=12 之前设置异常处理程序=]
由于您要发送 Toast 通知,因此您还需要设置 forceCloseDialogAfterToast
,因为假设 defaultExceptionHandler 是 Android 框架中的一个,它将显示强制关闭对话框,而您不会想要显示如果还显示 Toast。
它适用于 Android 5.0,但不适用于 Jellybean 设备。
@ReportsCrashes(
formKey = "", // This is required for backward compatibility but not used
formUri = "dummyurl",
reportType = org.acra.sender.HttpSender.Type.JSON,
httpMethod = org.acra.sender.HttpSender.Method.PUT,
formUriBasicAuthLogin="adminTest",
formUriBasicAuthPassword="adminTest",
mode = ReportingInteractionMode.TOAST,
resToastText = R.string.crash_toast_text)
public class Application extends Application {
@Override
public void onCreate() {
super.onCreate();
init();
ACRA.init(this);
Thread.setDefaultUncaughtExceptionHandler(sUncaughtExceptionHandler);
}
private UncaughtExceptionHandler sUncaughtExceptionHandler = new UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread thread, Throwable ex) {
Log.i(LogTag, "uncaughtException: ");
dummyMethod();
Thread.getDefaultUncaughtExceptionHandler().uncaughtException(
thread, ex);
}
};
}
ACRA 设置自己的 UncaughtExceptioHandler 执行错误报告,然后委托给之前存在的任何 UncaughtExceptionHandler。
因此,如果您希望在 ACRA 完成错误报告后调用 UncaughtExceptionHandler,则需要在 调用 调用 ACRA.init(this);
[=12 之前设置异常处理程序=]
由于您要发送 Toast 通知,因此您还需要设置 forceCloseDialogAfterToast
,因为假设 defaultExceptionHandler 是 Android 框架中的一个,它将显示强制关闭对话框,而您不会想要显示如果还显示 Toast。