admin管理员组文章数量:1635828
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
本文标签: IllegalArgumentExceptionnavigationJavalangunknown
版权声明:本文标题:java.lang.IllegalArgumentException: navigation destination xxx is unknown to this NavController 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://m.elefans.com/dongtai/1729215525a1190384.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论