Search Unity

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

Discussion in 'Scripting' started by farazk86, Oct 17, 2019.

  1. farazk86

    farazk86

    Joined:
    May 31, 2017
    Posts:
    195
    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: https://github.com/playgameservices/play-games-plugin-for-unity/issues/310

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

    Code (CSharp):
    1. using (AndroidJavaClass javaClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer")) {
    2.         AndroidJavaObject unityActivity = javaClass.GetStatic<AndroidJavaObject>("currentActivity");
    3.         unityActivity.Call<bool>("moveTaskToBack", true);
    4.     }
    But this is a hack and minimizes the app. I need it to quit.

    I tried the other command suggested there:
    Code (CSharp):
    1. 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
     
  2. Yoreki

    Yoreki

    Joined:
    Apr 10, 2019
    Posts:
    2,605
    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:
    https://unity3d.com/unity/whats-new/2018.4.0
    https://unity3d.com/unity/whats-new/2018.4.1
    https://unity3d.com/unity/whats-new/2018.4.2
    https://unity3d.com/unity/whats-new/2018.4.3
    https://unity3d.com/unity/whats-new/2018.4.4
    https://unity3d.com/unity/whats-new/2018.4.5
    https://unity3d.com/unity/whats-new/2018.4.6
     
    farazk86 and SparrowGS like this.
  3. jvo3dc

    jvo3dc

    Joined:
    Oct 11, 2013
    Posts:
    1,520
    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.