Answers for "how to make back button exit app on kotlin"

0

kotlin android click again to exit

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()
    }
Posted by: Guest on August-12-2020

Code answers related to "how to make back button exit app on kotlin"

Browse Popular Code Answers by Language