提问人:JunJaBoy 提问时间:5/31/2023 更新时间:5/31/2023 访问量:15
当 Thread.UncaughtExceptionHandler 调用 navigate() 时,应用停止
App stops when Thread.UncaughtExceptionHandler calls navigate()
问:
我正在尝试使 catch 全局应用程序例外。但是,当捕获异常时,应用程序将停止而不会崩溃。但是,UI 组件;像底部导航一样可以点击,并显示涟漪效应。但永远不要改变屏幕。DmsExceptionHandler
DmsExceptionHandler
internal class DmsExceptionHandler @Inject constructor(
private val context: Context,
private val appState: DmsAppState,
) : Thread.UncaughtExceptionHandler {
override fun uncaughtException(
thread: Thread,
exception: Throwable,
) {
when (exception) {
is CommonException.SignInRequired -> signInRequired()
else -> {
signInRequired() // todo replace
}
}
}
private fun signInRequired() {
appState.navigateToSignIn()
}
}
如果我不调用,应用程序不会停止。uncaughtException
signInRequired()
internal fun DmsAppState.navigateToSignIn() {
println("NAVIGATED TO SIGN IN")
this.navController.navigate(DmsRoute.Auth.route) {/*
popUpTo([email protected]) {
saveState = true
}*/
}
}
答: 暂无答案
评论