Fragment pressing back button

后端 未结 16 2349
清歌不尽
清歌不尽 2020-11-29 20:18

I am now having an activity containing fragments

[1] , [2] , [3] , [4]

If pressing buttons , [3] , it can be redirected to [4]

I would like to imp

16条回答
  •  無奈伤痛
    2020-11-29 21:03

    use this (in kotlin)

     activity?.onBackPressedDispatcher?.addCallback(this, object : OnBackPressedCallback(true) {
            override fun handleOnBackPressed() {
                // in here you can do logic when backPress is clicked
            }
        })
    

    i think this is the most elegant way to do it

提交回复
热议问题