- Home /
Send Application to background/Paused in Android
Currently i have my application "fully ended" by pressing Back Button in android device. Thus my application not exist in task manager anymore.
function Update(){
if(Input.GetKeyDown("escape"))
Application.Quit();
}
How do i make application is paused and still exist in the task manager when back button is pressed? It is the same effect when the home button is pressed.
Nope :(
So far, i use confirmation box whether the user really want to exit in case back button pressed accidentally
Right, it's quite incredible nobody has an answer to this??
I guess it's safe to say that Unity provides no way to move an app to the background then.
Answer by IMD · Nov 23, 2018 at 12:59 PM
Hi, so for making the Android back button send the app to the background you can use the following code in any Monobehaviour in the current scene:
void Update()
{
#if UNITY_ANDROID
//added for Android back button reaction
if (Input.GetKeyDown(KeyCode.Escape))
{
AndroidJavaObject activity = new AndroidJavaClass("com.unity3d.player.UnityPlayer").GetStatic<AndroidJavaObject>("currentActivity");
activity.Call<bool>("moveTaskToBack", true);
}
#endif
}
Your answer
Follow this Question
Related Questions
Android lag when home key is pressed 1 Answer
Differentiate App closed and minimized 0 Answers
Portrait Android app? 1 Answer
Android app freezing on splash screen 0 Answers