【问题标题】:Android UncaughtExceptionHandler not called if I use ACRA如果我使用 ACRA,则不会调用 Android UncaughtExceptionHandler
【发布时间】:2015-04-27 16:20:55
【问题描述】:

它适用于 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);
        }
    };
}

【问题讨论】:

  • 我不知道为什么它在 L 中工作,但这里的问题是你设置了两个 UncaughtExceptionHandler 一个你手动分配的,一个 ACRA 正在为你创建,这是不对的。跨度>

标签: android acra


【解决方案1】:

ACRA 设置自己的 UncaughtExceptionHandler 来执行错误报告,然后委托给它之前存在的任何 UncaughtExceptionHandler。

因此,如果您希望在 ACRA 完成错误报告后调用 UncaughtExceptionHandler,那么您需要在调用ACRA.init(this);

之前设置您的异常处理程序

由于您要发送 Toast 通知,因此您还需要设置 forceCloseDialogAfterToast,因为假设 defaultExceptionHandler 是 Android 框架中的一个,它将显示强制关闭对话框,如果还显示吐司。

【讨论】:

  • 这个我试过了,Thread.setDefaultUncaughtExceptionHandler(sUncaughtExceptionHandler); ACRA.init(这个);但还是不行,
  • 也将 forceCloseDialogAfterToast 设置为 true。
  • 我在调用 ACRA.init(this); 之前尝试过 Thread.setDefaultUncaughtExceptionHandle;这对我有用。感谢您的帮助
  • 注意:对前一个处理程序的委托仅在 1. 如果 ACRA.getConfig().mode() == ReportingInteractionMode.SILENT || (ACRA.getConfig().mode() == ReportingInteractionMode.TOAST && ACRA.getConfig() .forceCloseDialogAfterToast()) 为真,或 2. 如果 ACRA 未启用或 3. 如果 ACRA 自身抛出异常(检查 ErrorReporter.java)发生
猜你喜欢
  • 2014-06-01
  • 1970-01-01
  • 2015-05-04
  • 1970-01-01
  • 2020-10-09
  • 2010-12-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多