导航体系结构组件-登录屏幕 [英] Navigation Architecture Component - Login screen

查看:65
本文介绍了导航体系结构组件-登录屏幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正计划实施这样的导航:

我面临的问题是,当用户位于LoginFragmennt中并按返回按钮时,它再次加载LognFragment,即.卡在循环中.

I am planning to implement navigation like this:

The problem I face is when user is in LoginFragmennt and presses back button it again loads up LognFragment ie. stuck in loop.

我根据LoginnFragment #50512729>此答案.

I navigate to LoginnFragment using conditional navigation as per this answer.

如何正确实施呢?

推荐答案

我可以提出的解决方案之一是在您的活动onBackPressed方法内部进行覆盖,如果当前目标位置(在进行后按处理之前)是登录片段.

One of the solutions that i can propose is to override inside your activity onBackPressed method, and finish the activity if your current destination(before on back pressed handled) is login fragment.

override fun onBackPressed() {
    val currentDestination=NavHostFragment.findNavController(nav_host_fragment).currentDestination
    when(currentDestination.id) {
        R.id.loginFragment -> {
            finish()
        }
    }
    super.onBackPressed()
}

这篇关于导航体系结构组件-登录屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆