当发生崩溃时,我需要从头开始重新启动应用程序。
我使用以下代码重新启动应用程序:
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 ?
ACRA.getErrorReporter().handleException(...)