我正在使用Bugsnag进行自动错误报告,并希望在应用程序崩溃时执行一些额外的操作,例如重新启动。
问题:两者都单独工作,但没有结合起来。一旦我添加MyUncaughtExceptionHandler
,Bugsnag 就会停止报告。
应用程序
public class App extends Application {
@Override
public void onCreate() {
super.onCreate();
Bugsnag.init(this);
// "Breaks" Bugsnag:
Thread.setDefaultUncaughtExceptionHandler(
new MyUncaughtExceptionHandler(this, MainActivity.class));
}
}
MyUncaughtExceptionHandler
public class MyUncaughtExceptionHandler implements
java.lang.Thread.UncaughtExceptionHandler {
private final Context mContext;
private final Class<?> mActivityClass;
public MyUncaughtExceptionHandler(Context context, Class<?> c) {
mContext = context;
mActivityClass = c;
}
public void uncaughtException(Thread thread, Throwable exception) {
Bugsnag.notify(exception);
Intent intent = new Intent(mContext, mActivityClass);
mContext.startActivity(intent); // restarts the app
Process.killProcess(Process.myPid());
System.exit(0);
}
}
我已经尝试Bugsnag.notify(exception)
在MyUncaughtExceptionHandler
.
任何想法?提前致谢!