【发布时间】: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