The Android operating system has a built-in user interface to hide and close applications. Creating your own interface to close your application will create an inconsistent user experience between your application and other Android applications. Therefore, it’s not recommended to create your own interface to quit your application.
If you must programmatically close an Android application, use Activity.moveTaskToBack instead of Application.Quit. Activity.moveTaskToBack
pauses the application and moves it to the background, which is closer to the standard Android application lifecycle than what Application.Quit
does.
The following code example shows how to move your application to the back of the activity stack.
using UnityEngine;
public class QuitApplicationUtility
{
public static void MoveAndroidApplicationToBack()
{
AndroidJavaObject activity = new AndroidJavaClass("com.unity3d.player.UnityPlayer").GetStatic<AndroidJavaObject>("currentActivity");
activity.Call<bool>("moveTaskToBack", true);
}
}