Search Unity

Game restarts after pressing Home / Multitask Tray button.

Discussion in 'Android' started by Pedrohcg, Mar 22, 2018.

  1. Pedrohcg

    Pedrohcg

    Joined:
    Mar 25, 2015
    Posts:
    15
    Hello guys, I'm currently having an issue with my project and I think it's a 2017 unity version issue. Before the update I used this script to prevent my game from restarting after pressing the Home button or going to the Multitask tray:

    Code (CSharp):
    1. private void Update()
    2.     {
    3.         // Prevents game to close whenever the player clicks the home button
    4.         if (Input.GetKeyDown(KeyCode.Escape) || Input.GetKeyDown(KeyCode.Menu))
    5.         {
    6.             AndroidJavaObject activity = new  AndroidJavaClass("com.unity3d.player.UnityPlayer").GetStatic<AndroidJavaObject>("currentActivity");
    7.             activity.Call<bool>("moveTaskToBack", true);
    8.         }
    9.     }
    This was working perfectly in previous version prior to 2017.x.x.

    This is a big issue for me because I have an in-game system that let the player watch an Ad when he dies so he can restart the game where he left off, like a checkpoint, but if he chooses to click on the ad's application (redirecting him to app store), when he returns to the game, the game will be restarted making him losing progress and the bonus from watching the ad.

    I found some old fixes that tells me to modify the androidmanifest.xml in my "ProjectName/Assets/Plugin/Android" but the manifest I found there is completly different from their's (probably because is it too old) so I don't feel like editing it, may cause even further issues.

    If someone have an answer or can point out what I'm missing, I'd appreciate it.
    Thanks a lot.