Why not work back button with android navigation component

后端 未结 1 767
[愿得一人]
[愿得一人] 2021-01-28 09:42

this my Auth Activity

class AuthActivity : AppCompatActivity() {
    private lateinit var navController: NavController
    override fun onCreate(savedInstanceStat         


        
1条回答
  •  温柔的废话
    2021-01-28 10:17

    Your issue is not with the back button not working, it is that LiveData is for state, not events like your loginResponse. As LiveData is for events, it redelivers the previous response when you go back to your LoginFragment. This then triggers your navigate() call again, pushing you right back to your AcceptCodeFragment.

    As per the LiveData with SnackBar, Navigation, and other events blog post, LiveData cannot be directly used for events. Instead, you should consider using an event wrapper or another solution (such as a Kotlin Flow) that allow your events to only be handled once.

    0 讨论(0)
提交回复
热议问题