Advertisement
thanhlongxyz

Override Back pressed

Jun 24th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 0.42 KB | None | 0 0
  1.   private var doubleBackToExitPressedOnce = false
  2.     override fun onBackPressed() {
  3.         if (doubleBackToExitPressedOnce) {
  4.             //TODO showDialog
  5.             return
  6.         }
  7.  
  8.         this.doubleBackToExitPressedOnce = true
  9.         Toast.makeText(this, resources.getString(R.string.exit_toast), Toast.LENGTH_SHORT).show()
  10.  
  11.         Handler().postDelayed({ doubleBackToExitPressedOnce = false }, 2000)
  12.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement