导航架构组件 – 登录屏幕
我打算像这样实现导航:
我遇到的问题是当用户在LoginFragmennt
并按回按钮时它再次加载LognFragment
即。 卡在循环中。
我按照这个答案使用条件导航导航到LoginnFragment
。
如何正确实现这个?
我可以建议的解决方案之一就是覆盖你的活动onBackPressed方法,如果当前目的地(在后面按下处理之前)是登录片段,则完成活动。
override fun onBackPressed() { val currentDestination=NavHostFragment.findNavController(nav_host_fragment).currentDestination when(currentDestination.id) { R.id.loginFragment -> { finish() } } super.onBackPressed() }