[Solved] Exit app on double tap (android app)


in c#

void Update(){
   if (Input.GetKeyDown(KeyCode.Escape)) 
    Application.Quit(); 
 }

or in .js

function Update(){
   if (Input.GetKeyDown(KeyCode.Escape)) 
    Application.Quit(); 
 }

This is the function for exit app when back button pressed, if you want to exit the app when back button pressed twice, implement the logic in the java code you have posted in question into equivalent code in unity i.e initialise a variable to store current time in millis on first back button press and show message to press once again to exit, and if next back button press is within two seconds of first press, then exit app.

If you want this to work on a button click etc, implement the same technique and call Application.Quit() instead of super.onBackPressed() in java.

Hope this helps.

1

solved Exit app on double tap (android app)