App stops when Thread.UncaughtExceptionHandler calls navigate()

24 Views Asked by At

I am trying to make DmsExceptionHandler catch global application exception. But when the DmsExceptionHandler catches the exception, the application stops without crashing. However, UI components; like bottom navigation can be clicked, and ripple effect is shown. But never changes the screen.

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()
    }
}

If i make uncaughtException do not call signInRequired(), the application does not stop.

internal fun DmsAppState.navigateToSignIn() {
    println("NAVIGATED TO SIGN IN")
    this.navController.navigate(DmsRoute.Auth.route) {/*
        popUpTo([email protected]) {
            saveState = true
        }*/
    }
}
0

There are 0 best solutions below