📜  kotlin android 再次点击退出 - Kotlin 代码示例

📅  最后修改于: 2022-03-11 14:53:33.027000             🧑  作者: Mango

代码示例1
private var backPressedTime:Long = 0
lateinit var backToast:Toast
   override fun onBackPressed() {
            backToast = Toast.makeText(this, "Press back again to leave the app.", Toast.LENGTH_LONG)
        if (backPressedTime + 2000 > System.currentTimeMillis()) {
            backToast.cancel()
            super.onBackPressed()
            return
        } else {
            backToast.show()
        }
        backPressedTime = System.currentTimeMillis()
    }