Quit program on Android

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
Arctichorse9
Posts: 25
Joined: Wed Sep 25, 2024 11:26 pm
Location: New York City
Contact:

Quit program on Android

Post by Arctichorse9 »

Hi. Using your Menu Framework which is great but have a problem quitting the application on Android. Application quit doesn't work on Android. Unity suggests using something like

Code: Select all

{
        AndroidJavaObject activity = new AndroidJavaClass("com.unity3d.player.UnityPlayer").GetStatic<AndroidJavaObject>("currentActivity");
        activity.Call<bool>("moveTaskToBack", true);
    }
But I don't know how to work that into the SaveHelper.cs Halt Program function.

It handles quitting the application on the Unity Standalone and Editor choices but somehow have to add Android. Would it be if UNITY_ANDROID ??

And would it be ok to put the above code Unity suggests after that?

Thanks for any help.
User avatar
Tony Li
Posts: 22104
Joined: Thu Jul 18, 2013 1:27 pm

Re: Quit program on Android

Post by Tony Li »

Hi,

Yes, that's fine. Normally, I think you just let the player minimize or close the app, but to halt it manually you can add it:

Code: Select all

public void HaltProgram()
{
#if UNITY_ANDROID
    AndroidJavaObject activity = new AndroidJavaClass("com.unity3d.player.UnityPlayer").GetStatic<AndroidJavaObject>("currentActivity");
    activity.Call<bool>("moveTaskToBack", true);
#else
    Application.Quit();
#endif

#if UNITY_EDITOR
    UnityEditor.EditorApplication.isPlaying = false;
#endif
}
Arctichorse9
Posts: 25
Joined: Wed Sep 25, 2024 11:26 pm
Location: New York City
Contact:

Re: Quit program on Android

Post by Arctichorse9 »

This works perfectly on Android. I had to type it in rather than copy and paste because the code editor did not like the pasted quotation marks. : ) Thanks very much.
User avatar
Tony Li
Posts: 22104
Joined: Thu Jul 18, 2013 1:27 pm

Re: Quit program on Android

Post by Tony Li »

Glad to help! I think I fixed the quotes issue above. Thanks for letting me know.
Post Reply