- Home /
Android how to moveTaskToBack and minimze the app but not terminate it?
In java this is simply act.moveTaskToBack(true); In Unity I can only find Application.Quit() which appears to fully terminate the application. We want our users to be able to minimize the app with a back key press when they're at the app's main menu. I have searched the forums here as thoroughly as I can and all I can find are uses of Application.Quit() which is, for me, terminating the app.
Thanks!
Yeah I want to be able to do it on back key press which is standard to do in android when at an app's home screen. Found my own answer below.
Answer by Naphier · Dec 10, 2014 at 03:03 PM
AndroidJavaObject activity = new AndroidJavaClass("com.unity3d.player.UnityPlayer").GetStatic<AndroidJavaObject>("currentActivity");
activity.Call<bool>("moveTaskToBack" , true);
Works like a charm! Thanks to jeli23 http://jeli23-unity.blogspot.com/2014/05/unity-android-back-button-problem.html?showComment=1418223248020#c1011871436739340057
Answer by andrew_pearce · Apr 08, 2019 at 08:11 AM
I would like also to mention important part of working solution by Naphier. Make sure that you call "new AndroidJavaClass()" within start() method, and never within lambda function, coroutine and etc. Just tested and works awesome!