DOUBLE PRESS BACK BUTTON TO EXIT APP || KOTLIN ANDROID STUDIO

KOTLIN || ANDROID STUDIO || DOUBLE TAP BACK BUTTON TO EXIT APP








Click here for video guidance 


STEP 1: CREATE A NEW PROJECT WITH EMPTY ACTIVITY


STEP 2: OPEN MainActivity.kt FILE.


STEP 3: PASTE FOLLOWING CODE IN MainActivity.kt FILE

private var doubleBackToExitPressedOnce = false
override fun onBackPressed() {
if (doubleBackToExitPressedOnce) {
super.onBackPressed()
return
}

this.doubleBackToExitPressedOnce = true
Toast.makeText(this, "Please click BACK again to exit", Toast.LENGTH_SHORT).show()

Handler(Looper.getMainLooper()).postDelayed(Runnable { doubleBackToExitPressedOnce = false }, 2000)
}


STEP 3: IF ANY RED MARKS OCCUR, CLICK ON THAT AND PRESS THE KEY ALT+ENTER.


STEP 4: DONE! NOW LAUNCH THE APP.


tags : Android studio tutorial, double press back button to exit app, kotlin , java, 

Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.
Site is Blocked
Sorry! This site is not available in your country.