如果主线程崩溃,如何从 UncaughtExceptionHandler 启动活动?
如果检测到未处理的异常,我正在尝试启动错误报告活动。问题在于主线程抛出异常。如果主线程崩溃,有什么方法可以启动活动吗?
I am trying to start an error-reporting activty if unhandled exception detected. The problem is with exceptions thrown from main thread. Is there any way to start an activity if main thread crashed?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我见过的用于在
UncaughtExcpetionHandler< 中捕获错误的方法/code>
是将崩溃数据写入文件,然后根据崩溃数据文件的存在,在应用重启时启动错误处理
Activity
。根据您希望
Activity
执行的操作,这可能适合您。The approach I've seen used for error catching in an
UncaughtExcpetionHandler
is to write the crash data out to file and then start the error handlingActivity
when the application is restarted based on the existence of the crash data file.Depending on what you want your
Activity
to do, this might work for you.我认为这是错误的做法。您需要做的是确保捕获这些异常,并在捕获它们时弹出错误报告活动。
I think this is the wrong way to go about it. What you need to do is make sure you catch those exceptions, and pop up an error-reporting activity when you catch them.
您可以将属性
android:process=":report_process"
添加到
元素,该元素引用AndroidManifest.xml
。默认情况下,属于同一应用程序的活动将在由您的包名称标识的同一进程中运行。通过设置 android:process 属性,您可以覆盖它。以
:
开头的android:process
引用包内的私有标识符,以便您可以在新进程中启动 Activity,而不会与其他包的进程发生冲突。You can add attribute
android:process=":report_process"
to the<activity>
element which refers to your bug report activity inAndroidManifest.xml
.By default, activities belong to the same appliction would run in the same process identified by your package name. By setting
android:process
attribute, you can override this.android:process
starting with:
refers to a private identifier within your package, so that you can start the activity in a new process without conflicting other packages' process.