java - Android/Java:UncaughtExceptionHandler 和 Bugsnag 并行?
问题描述
我正在使用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
.
任何想法?提前致谢!
解决方案
I spotted your post here but do always reach out to us via Bugsnag support if you want a guaranteed response.
The issue is that when you're calling Thread.setUncaughtExceptionHandler
, you're removing the handler which Bugsnag sets up here:
https://github.com/bugsnag/bugsnag-android/blob/2308eb6c706f66495dea116acf619f695530dff4/sdk/src/main/java/com/bugsnag/android/ExceptionHandler.java#L31
You'd need to call the original handler in order for Bugsnag to detect anything.
Note that killing the process and launching a new intent is not an approach we'd recommend in general in an Android app.
推荐阅读
- java - Hibernate、@JoinTable 和 JoinColumns 进行不包含非空值的插入
- python - 试图找到一种聪明的方法来查找给定字符串中的关键字索引
- c# - 变量中的 UWP/C# 日期存储
- sql - SQL Server Temp Table to a Select Distinct Count Distinct question
- javascript - 为什么 redux 上的默认状态初始化为 false 而不是空的?
- vb.net - 如何使用参数调用 Visual Basic API
- selenium-webdriver - 如何在 selenium webdriver 中等待页面加载
- javascript - JavaScript 坏了
- javascript - 从 VRPose.orientation Quarternion 获取欧拉角
- java - 访问 docker 环境之外的数据库