android - 如何从 DaggerApplication 中的 UncaughtExceptionHandler 启动活动
问题描述
我正面临着类似的情况,具有相同的奇怪行为:意图不会触发,崩溃对话框也不会显示,并且应用程序在崩溃后自行关闭。Logcat
显示如下错误:
E/InputEventSender: Exception dispatching finished signal.
E/MessageQueue-JNI: Exception in MessageQueue callback: handleReceiveCallback
E/MessageQueue-JNI: java.lang.NumberFormatException: For input string: "7512186516213"
and so on....
D/Android Runtime: Shutting down VM
我们如何从UncaughtExceptionHandler
in开始活动DaggerApplication
?
这是我的代码。我在applicationContext
到处使用,我已经在我的文件中注册了ExceptionDisplay
活动。Manifest
我确信他们DaggerApplication
可以像Application
上课一样处理这个问题,但不幸的是我自己无法解决它。
class IpunktApp : DaggerApplication() {
override fun applicationInjector(): AndroidInjector<out DaggerApplication> =
DaggerAppComponent.factory().create(this)
private lateinit var defaultUEH: Thread.UncaughtExceptionHandler
private val unCaughtExceptionHandler = Thread.UncaughtExceptionHandler { thread, ex ->
val stringWriter = StringWriter()
ex?.printStackTrace(PrintWriter(stringWriter))
val exception = stringWriter.toString()
saveLogs(exception.toByteArray(), applicationContext)
applicationContext.startActivity(Intent(Intent(applicationContext, ExceptionDisplay::class.java).apply {
putExtra("error", exception)
addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK)
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
}))
defaultUEH.uncaughtException(thread, ex)
exitProcess(1)
}
override fun onCreate() {
super.onCreate()
setupExceptionHandler()
}
private fun setupExceptionHandler() {
try {
defaultUEH = Thread.getDefaultUncaughtExceptionHandler()
Thread.setDefaultUncaughtExceptionHandler(unCaughtExceptionHandler)
} catch (e: Exception) {
e.printStackTrace()
}
}
}
任何建议表示赞赏。提前致谢。
解决方案
推荐阅读
- c# - 获取代码中的版本号.Net Core 3 WPF Sideload
- python-2.x - 关于如何更新刽子手游戏字符串的更好主意
- python-3.x - 使用python从json中获取价值
- python - 在 Python 中使用 Dask 并行运行函数
- python - 如何从流量计中获取数据并在我的 python 代码中使用它?
- angular - Angular 8 不会等到新值呈现在视图上
- elasticsearch - 使用 Logstash 批量创建和批量更新 ElasticSearch 索引文档
- c++ - c++:静态链接同一个库的不同版本?
- pandas - 替换字符串中不全是字母的短语 Pandas
- powershell - 从 EC2 usedata 启动 Exe 并让它在桌面上运行