Navigation Architecture Component - Login screen

前端 未结 3 2159
一整个雨季
一整个雨季 2020-12-09 22:24

I am planning to implement navigation like this:
\"enter
The problem I face is when us

3条回答
  •  旧巷少年郎
    2020-12-09 23:06

    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()
    }
    

提交回复
热议问题