java.lang.IllegalArgumentException: navigation destination xxx is unknown to this NavController

java.lang.IllegalArgumentException: navigation destination xxx is unknown to this NavController

直接复制我在stackflow中的答案了

It occurs to me when I press back button for two times。At frist,I intercept KeyListener and override KeyEvent.KEYCODE_BACK. I add code below at function named “OnResume” of Fragment. This question is solved.

override fun onResume() {
super.onResume()
view?.isFocusableInTouchMode = true
view?.requestFocus()
view?.setOnKeyListener { v, keyCode, event ->
if (event.action == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_BACK) {
activity!!.finish()
true
}
false
}
}
When it happen to me second time and it`s status is the same as the fisrt one,I find that I maybe use adsurd function.let’s analyze these situations.

Firstly, FragmentA navigate to FragmentB ,then FragmentB navigate to FragmentA ,then press back button ,the crash appear;

Secondly, FragmentA navigate to FragmentB ,then FragmentB navigate to FragmentC ,FragmentC navigate to FragmentA ,then press back button ,the crash appear;

So I think pressing back button, FragmentA will return to FragmentB or FragmentC ,then it cause login mess,finilly,I find that the function of popBackStack can be used of back rather than navigate

NavHostFragment.findNavController(this@TeacherCloudResourcesFragment).
.popBackStack(
R.id.teacher_prepare_lesson_main_fragment,false
)
So far ,the problem is really solved

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值