- Home /
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.
Lots of peeople seem to find that Application.Quit() from an OnGUI button doesnt seem to work.
Answer by meat5000 · Oct 08, 2013 at 07:52 PM
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.
Answer by satya144 · Dec 19, 2013 at 08:21 AM
Well application.quit() doesn't work in unity but after building and running it will work on your device.
Answer by Ereptor · Oct 08, 2013 at 07:43 PM
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.
Answer by smallbit · Oct 08, 2013 at 07:52 PM
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
Answer by hari2015 · Feb 12, 2018 at 05:27 AM
if(Input.GetKeyDown(KeyCode.Escape)) {
Application.Quit();
}
Your answer
Follow this Question
Related Questions
Proper way for Quit Application 2 Answers
How do I Force Application to Quit if no internet connection available 1 Answer
How do i stop mUnityPlayer.quit() closing the entire android app? 1 Answer
Path for Assets/Textures folder File in Android 2 Answers
Some questions about unity app's tcp connection state in Android sleep mode 0 Answers