我正面临着类似的情况,具有相同的奇怪行为:意图不会触发,崩溃对话框也不会显示,并且应用程序在崩溃后自行关闭。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()
}
}
}
任何建议表示赞赏。提前致谢。