I'm facing a similar scenario like this with the same strange behaviour: The intent will not fire, the crash dialog won't be showed either and the app closes by itself after crashing. Logcat
shows the error like this:
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
How can we start an activity from UncaughtExceptionHandler
in DaggerApplication
?
Here is my code. I'm using the applicationContext
everywhere and I have registered the ExceptionDisplay
activity in my Manifest
file. I'm sure that the DaggerApplication
can handle this as well as the Application
class, but I unfortunately can't solve it by myself.
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()
}
}
}
Any advice is appreciated. Thanks in advance.