- Home /
Quit or close unity on button click and send user to Android native app
I am developing unity game which will open through Android native app. I have created a plugin i.e. JAR file which have methods for two way communication and putted it in Assets/Plugins/Android/A.jar. Now I'm able to open unity from Android native app. In unity game there is a Back button which sends user to Android native app when pressed. But I want unity game to be closed/quit completely on this button click.
I have tried Application.Quit(); and Application.close();. But getting exception or error when unity code merged with Android native app.
private static AndroidJavaObject context = null; private static AndroidJavaObject activityContext = null;
void Start() { #if UNITY_ANDROID AndroidJavaClass activityClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); activityContext = activityClass.GetStatic("UnityPlayerActivity"); context = activityContext.Call("getApplicationContext"); #endif }
//invoke on Button click public static void GoBackToAndroid() { Debug.Log("[Unity Log] - Back button pressed"); Resources.UnloadUnusedAssets(); #if UNITY_ANDROID using (AndroidJavaClass pluginClass = new AndroidJavaClass("com.communication.bridge.")) { pluginClass.CallStatic("HideUnityInProgress"); } #endif Application.Quit(); }
Any link, piece of code, suggestions will be appreciated.
Your answer
![](https://koobas.hobune.stream/wayback/20220612123829im_/https://answers.unity.com/themes/thub/images/avi.jpg)