Android - How To Override the “Back” button so it doesn't Finish() my Activity?

后端 未结 10 1251
粉色の甜心
粉色の甜心 2020-11-22 08:07

I currently have an Activity that when it gets displayed a Notification will also get displayed in the Notification bar.

This is so that when the User presses home a

10条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-22 08:25

    In Kotlin:

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

    For more information you can check this.

    There is also specific question about overriding back button in Kotlin.

提交回复
热议问题