I am using Navigation Component in my app , recently it was working correctly but after updating project to AndroidX
I am getting error navigation destination DESTINATION_NAME is unknown to this NavController
only if that destination(Which I'm going to open) is previously closed from itself using navController.popBackStack()
. Also, There is no error if I close DESTINATION fragment from MainActivity
, But Error only Occurs fragment is closed from itself using popBackStack
. like below
DestinationFragment
viewModelOfActivity.handleBackButton.observe(this, Observer {
Navigation.findNavController(requireActivity(), R.id.main_nav_host).popBackStack()
//CALLING popBackStack() HERE CAUSING PROBLEM WHEN REOPNING THIS DESTINATION(or frg ) AGIAN
})
MainActivity
override fun onBackPressed() {
if (myViewModel.isDefaultBehaviour.value == true) {
super.onBackPressed()
} else{
myViewModel.handleBackButton.value=true
//NO ERROR IF HANDLE BACK BUTTON HERE ie->findNavController(R.id.main_nav_host).popBackStack()
//INSTEAD OF myViewModel.handleBackButton
}
}
I Have also checked related Question but no help Similar Question.
NOTE: I am using the latest version of the navigation library (alpha05)