Application.quit() not working on android

Application quit works on escape button (back on my galaxy s2) but doesn’t work when in the GUI.button.

Any ideas how can i fix it ?

i use temporal exit function which will have more things in it in the future

	if(GUI.Button(new Rect((int)menuMainX,340,240,60), "Exit")) {

				Exit();

			}

   void Exit()
	{
		Application.Quit();
		
	}

I tried to put it directly under gui button same result.

You can script it for the back button but iOS and Android have a User Discretion policy on app quit these days. Basically back button will normally lose focus and pause but the app moves to background. You can set it to quit but you should show a dialogue to confirm quit for good Android practise, I believe.

I read that back button is the same as Escape key but I’m yet to try it.

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

Edit:

Just tried the following on a GUITexture in my touch routine.

if(menuButtons.HitTest(GUIRay).name == "QuitMenuButton" && theTouch.phase == TouchPhase.Began)
			{
				Application.Quit();
			}

It Quit the App. However Android 4.3 showed strange behaviour. The program remained inside my open apps list. If I went back to the game in the list it reloaded the game from start. So although the game quits it seems to not Unload fully.

I haven’t worked in Android before, but I know that Application.Quit(); does not work in the web version. We had to remove Quit buttons from the web version of our game, instead allowing for the user to default to the “retry” option, or simply use their browser to navigate away.

What is the convention for Android? It’s possible that Application.Quit(); might not be the proper choice.

I have read the documentation and I know that this command wont work in PIE and web but on android should be working properly…

I have found a thread from 2011 in which one unity user used System.Diagnostics.Process.GetCurrentProcess().Kill();

instead, but there is no additional info

Well application.quit() doesn’t work in unity but after building and running it will work on your device.

if(Input.GetKeyDown(KeyCode.Escape)) {

Application.Quit();

}