如何从自定义的uncaughtException处理程序中调用ACRA?

时间:2016-09-05 09:43:57

标签: android exception-handling acra uncaught-exception

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

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?

1 个答案:

答案 0 :(得分:0)

ACRA.getErrorReporter().handleException(...)