how to handle back pressed in Kotlin

后端 未结 2 1667
抹茶落季
抹茶落季 2021-01-19 07:06

my app having only two base activity and several fragment,, i want to display an Exit alert when user reach particular base fragment by clicking back press

o         


        
2条回答
  •  情书的邮戳
    2021-01-19 07:51

    You can just:

        val callback = requireActivity().onBackPressedDispatcher.addCallback(this) {
            // Handle the back button event
        }
    

    For more information you can check this.

提交回复
热议问题