Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Need Help: How to handle incoming calls during game play

Discussion in 'Android' started by kingdutka, Mar 24, 2012.

  1. kingdutka

    kingdutka

    Joined:
    Feb 1, 2011
    Posts:
    129
  2. Moredice_legacy

    Moredice_legacy

    Joined:
    Jan 31, 2010
    Posts:
    101
    Try to use this:

    // Make the game run even when in background
    Application.runInBackground = true;

    Place this in the awake function (make one if it's not there) of your script and set it to false. Your application will pause/freeze when either an event such as a call happens, or the home button is pressed. Your app should pick up right where you were interrupted. And you can use the OnApplicationPaused() function to pop up a nice menu for the user to see when he/she gets back into the app.
     
  3. kingdutka

    kingdutka

    Joined:
    Feb 1, 2011
    Posts:
    129
    I tried this and got the exact same results. Call wouldn't answer when I pushed the answer button and when I went back into the game, it had restarted and was on my main menu. I placed the code in 2 different scripts in the Awake() function (one in my main menu and one in Level 1).
     
  4. ScurvyKnave

    ScurvyKnave

    Joined:
    Mar 27, 2012
    Posts:
    3
    I'm having exactly the same problem, unfortunately. Others are as well, seems to be a common reason for apps being rejected on the Amazon Store. I think the problem may only be present on some phones (when testing I don't experience it, but others have reported it). Very frustrating.

    The other builds have the "run in background" option as a player setting, but not so for Android, which makes me wonder whether that option is even valid for Android builds. To further confuse the issue, I've read in another thread that Application.runInBackground must be set to false, not true as indicated above.
     
  5. Chris-Clark

    Chris-Clark

    Joined:
    Jan 16, 2012
    Posts:
    130
    You not only need to suspend your app like that, you need to remember exactly where the user was. Android may kill it at any moment because another app needs memory.

    So you'd want to detect when the game suspends and save the state. If the user comes back and it is still in memory, nothing was lost. But if it gets killed you can recover. So when you start the game, from scratch, you check to see if there is a saved state. If there is you load everything back and recreate the place the player was at the last time the app suspended.

    Sorry I searched Google for a bit and can't find the code you need to detect a suspend. I'm sure I've seen it before though. That was what my next step was going to be in developing my Android game.