Version: 2022.3
Language : English
Handle Android crashes
Building and delivering for Android

Quit a Unity Android application

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);
    }
}

Additional resources

Handle Android crashes
Building and delivering for Android
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961