- Home /
How to Exit Application in Android on Back Button
Hello All I need code to exit my application when I press back button on android device. But It seems that " Application.Quit()" is not executing. Please help
Answer by ina · Dec 26, 2012 at 10:32 AM
void Update(){
if (Input.GetKeyDown(KeyCode.Escape))
Application.Quit();
}
or in .js
function Update(){
if (Input.GetKeyDown(KeyCode.Escape))
Application.Quit();
}
this peice of text you have written is no an answer, you should have typed it above in the comment section.
Thank you, how to make it global ? Cause it work only in the scene that the script is atached. In my case the $$anonymous$$ainCamera. (NO_OB Here).
To make it global, use a DontDestroyOnLoad Game Object
Include the code in the Game Object builded in this tutorial:
How to just pause the application and not quit? I mean put it into backround like normal backbutton?
Answer by zzeeshann · May 15, 2016 at 03:01 PM
if (Input.GetKeyUp(KeyCode.Escape))
{
if (Application.platform == RuntimePlatform.Android)
{
AndroidJavaObject activity = new AndroidJavaClass("com.unity3d.player.UnityPlayer").GetStatic<AndroidJavaObject>("currentActivity");
activity.Call<bool>("moveTaskToBack", true);
}
else
{
Application.Quit();
}
}
This code is in C# if the user is on Android device or on PC the app will exit.
what language is this? and post with some explanations..
Answer by Muhammad Salman · Jun 01, 2016 at 06:03 AM
It will only work in the case of android only. if(Input.GetKeyDown(KeyCode.Escape)) {
Application.Quit();
}