Application.Quit() won't work on Android

Hi there,

I am trying to make the application quit itself when you press the back/return key of a Android phone.

I tried putting this code in the update of a script attached to a gameObject that is present in all my scenes, because of DontDestroyOnLoad:

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

I just tested something to see if I get inside the if, when playing on my phone. And I get there. Application.Quit() is the issue here. I hope someone can help me and explain how I can quit the app in Android.

Thanks! :slight_smile:

You could try this approach with quotation marks, this is how I found it in the manual when I needed it to work. I don’t know why your code doesn’t work though.

    void Update() {
        if (Input.GetKey("escape"))
            Application.Quit();
    }

What exactly does “won’t work” mean? What happens? Nothing?

I haven’t created any Android app recently, but it did work just fine in the past. Keep in mind that when you quit an app on android it will still show up in the “recent apps list”. Apps on that list can be in two different states: terminated or paused. When you press the “Home” button the app get paused and moved into the background. Such an app can be terminated at any time by the OS when it requires the memory.

However if you call Application.Quit() the application gets terminated immediately. However from the users point of view there’s no different how the app appears on the recent apps list. You will notice the difference when you try to activate the app again. A terminated app need to restart from scratch while a paused app that hasn’t been terminated by the OS yet can immediately resume.

If you call Application.Quit and nothing happens that would be a bug. However when it actually leaves the app you should be more clear what behaviour you observed. I actually doubt that it suddenly doesn’t work anymore.

It just doesn’t do anything. I now replaced the line with “System.Diagnostics.Process.GetCurrentProcess().Kill();”

So it just kills the process. Works like a charm but I am still confused why Application.Quit() just won’t do anything at all.

I noticed that Application Quit only works once the application is built and installed on the Android. It does not work in the Editor.