Announcements, support questions, and discussion for the Dialogue System.
Arctichorse9
Posts: 25 Joined: Wed Sep 25, 2024 11:26 pm
Location: New York City
Contact:
Post
by Arctichorse9 » Mon Nov 18, 2024 5:33 am
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.
Tony Li
Posts: 22110 Joined: Thu Jul 18, 2013 1:27 pm
Post
by Tony Li » Mon Nov 18, 2024 7:33 am
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:
Post
by Arctichorse9 » Mon Nov 18, 2024 8:36 pm
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.
Tony Li
Posts: 22110 Joined: Thu Jul 18, 2013 1:27 pm
Post
by Tony Li » Mon Nov 18, 2024 9:31 pm
Glad to help! I think I fixed the quotes issue above. Thanks for letting me know.