I have customized back button. when I click on it, the application crashes after a second. here is the code: error log
private var mBackPressed: Long = 0
private val timeInterval = 2000
private fun configBackPress() {
requireActivity().onBackPressedDispatcher.addCallback(this, true) {
when {
mBackPressed + timeInterval > System.currentTimeMillis() -> {
requireActivity().onBackPressedDispatcher.onBackPressed()
}
else -> {
Snackbar.make(
requireActivity().findViewById(android.R.id.content),
getString(R.string.press_once_again_back_button_to_exit),
Snackbar.LENGTH_SHORT
)
.setAnchorView(viewBinding.vSnackBarHelper)
.show()
mBackPressed = System.currentTimeMillis()
}
}
}
}
when the user click two times on back button, the back should work.