I have a SystemBackButtonHandler which handles back press, but I have the following error in Logcat
java.lang.ClassCastException: androidx.navigation.NavBackStackEntry cannot be cast to androidx.activity.ComponentActivity
I only understand that NavBackStackEntry cannot be cast to ComponentActivity, but I don't understand how to resolve it.
at com.example.bettehomes.navigation.SystemBackButtonHandlerKt.SystemBackButtonHandler(SystemBackButtonHandler.kt:48)
at com.example.bettehomes.presentation.authscreens.LoginScreenKt.LoginScreen(LoginScreen.kt:104)
at com.example.bettehomes.navigation.NavHostKt$AppNavigation$2$3.invoke(NavHost.kt:49)
at com.example.bettehomes.navigation.NavHostKt$AppNavigation$2$3.invoke(NavHost.kt:48)
@Composable
internal fun SystemBackButtonHandler(onBackPressed: () -> Unit) {
CompositionLocalProvider(
LocalBackPressedDispatcher provides LocalLifecycleOwner.current as ComponentActivity
) {
ComposableHandler {
onBackPressed()
}
}
}