【问题标题】:How do I invoke ACRA from a custom uncaughtException handler?如何从自定义 uncaughtException 处理程序调用 ACRA?
【发布时间】:2016-09-05 09:43:56
【问题描述】:

发生崩溃时,我需要从头重新启动应用程序。
我正在使用此代码重新启动应用程序:

public class MyExceptionHandler implements
        java.lang.Thread.UncaughtExceptionHandler {
    private final Context myContext;
    public MyExceptionHandler(Context context) {
        myContext = context;
    }
    public void uncaughtException(Thread thread, Throwable exception) {
        StringWriter stackTrace = new StringWriter();
        exception.printStackTrace(new PrintWriter(stackTrace));
        System.err.println(stackTrace);// You can use LogCat too
        Intent intent = new Intent(myContext, Initialsetup.class);
        String s = stackTrace.toString();
        //you can use this String to know what caused the exception and in which Activity
        intent.putExtra("uncaughtException",
                "Exception is: " + stackTrace.toString());
        intent.putExtra("stacktrace", s);
        Log.d("bugFix4","Handling crash");
        myContext.startActivity(intent);
        Process.killProcess(Process.myPid());
        System.exit(0);
    }
}

我还想使用 ACRA 以电子邮件的形式发送错误报告。
有什么方法可以从自定义 UncaughtExceptionHandler 调用 ACRA 吗?

【问题讨论】:

    标签: android exception-handling acra uncaught-exception


    【解决方案1】:
    ACRA.getErrorReporter().handleException(...)
    

    【讨论】:

    • 我什么时候打电话?
    • uncaughtException 方法中。在你终止进程之前。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-13
    • 1970-01-01
    • 2014-06-25
    • 2021-07-20
    • 2015-03-01
    相关资源
    最近更新 更多