Is there any way to quit the game without using Application.Quit()?

For some reason (known bug in Unity 2018.3 for Android) Google Play services stops working after Application.Quit() is used. More information on this here: Application.Quit () makes it unstable on Android · Issue #310 · playgameservices/play-games-plugin-for-unity · GitHub

I finally got play services to work after using the work around suggested there which was to replace Application.Quit() with below:

using (AndroidJavaClass javaClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer")) {
        AndroidJavaObject unityActivity = javaClass.GetStatic<AndroidJavaObject>("currentActivity");
        unityActivity.Call<bool>("moveTaskToBack", true);
    }

But this is a hack and minimizes the app. I need it to quit.

I tried the other command suggested there:

System.Diagnostics.Process.GetCurrentProcess().Kill();

But that does not do anything.

This bug was fixed in Unity 2018.4 but I’m at the deployment stage of my game, beta testing is done and am about to go public and at this stage I just cannot update Unity and risk breaking anything.

So any way to make the app quit without using Application.Quit()?

Thanks

Other than quitting the application and killing the process, i cant really think of anything. There is probably some way to make killing the process work, so if you really dont want to upgrade, i’d look deeper into this.

That said, the releases from 2018.4.0 to 2018.4.6 (where your fix is) are nearly 100% fixes. So i’d consider the risk of it breaking something to be very low. You may just wanna create some testing branch, update to 2018.4.6 there and then do some basic testing on all devices you have available. If this does not give you any reasons to assume something broke, i’d personally probably go with it. Here are all changelogs you may wanna have a look at; if you dont use these features, then these fixes should not concern you too much:

2 Likes

Not that you like to hear this, but Android (and iOs) apps are not supposed to quit at all. They are supposed to be designed to keep running. You can detect the change in state using OnApplicationPause.