Fast App Switching

Hi all,

Sorry if this is in the wrong place to be asking this question, but I’ve been looking around the forums and can’t seem to figure out how to implement support for fast app switching in my game.

What code do I need to add as to have the game suspend itself and keep its state to work with iOS fast app switching?

Thanks!
Logan [import]uid: 44896 topic_id: 7837 reply_id: 307837[/import]

Can anybody help me out? [import]uid: 44896 topic_id: 7837 reply_id: 27988[/import]

Do you mean multitasking? Corona does not support that feature yet. [import]uid: 11809 topic_id: 7837 reply_id: 28020[/import]

Yeah, that’s what I meant.
Oh well.

Thanks! [import]uid: 44896 topic_id: 7837 reply_id: 28021[/import]

As of Build 484, there is now support for this. All you need to do is add the following line into your build.settings:

[blockcode]
settings = {
iphone =
{
plist =
{
UIApplicationExitsOnSuspend = false
}
}
}
[/blockcode] [import]uid: 52430 topic_id: 7837 reply_id: 32379[/import]

The game state is kept after switching back ? [import]uid: 12088 topic_id: 7837 reply_id: 32397[/import]

@yuewah: I personally tested the code above (added to build.settings) with one of my personal projects, and I can confirm that with the latest stable release (Build 484) it works perfectly.

The app state is preserved after pressing the home button and going back into the app :slight_smile: [import]uid: 52430 topic_id: 7837 reply_id: 32399[/import]

I had implemented saving game state with SQLite literally the night before .484 became available. Then I ripped that functionality back out because the new multitasking is so much better than doing it that way. [import]uid: 12108 topic_id: 7837 reply_id: 32684[/import]

Just another vote of confidence for the new feature – built my game with it last night to see if I need to do anything other than set that value to false, and nope! On the device, in the middle of a puzzle I clicked the Home button, did something else, and then went back to my game…

…where it resumed exactly where I had left it, countdown timer and all. Nice!

Jay
[import]uid: 9440 topic_id: 7837 reply_id: 32743[/import]

Even with this feature we still need to deal with saving for pre iOS 4 devices right? [import]uid: 19626 topic_id: 7837 reply_id: 32965[/import]

@robmiracle: Yes, if your app is supporting devices below iOS 4, then you’ll have to still handle it manually (as do all apps for below iOS4, not just ones made with Corona).

Great reminder though! --Thanks [import]uid: 52430 topic_id: 7837 reply_id: 32970[/import]

I’m developing some kind of stopwatch app where I use “system.getTimer()” to measure the elapsed time in msec.

A few weeks ago I asked about support for this fast application switching as I need the user to switch to other apps while the timer is running… so I was pretty happy with this announcement for support.

However, it seems that this timer used by system.getTimer() get also stopped by the system when you switch, and resumes when you come back, which is not what I need.

Is that the correct/intended functionality of system.getTimer() ?

Are there any other options to measure the real elapsed time in msec since the app launched?

The ability to enable this fast switching while keeping my timer running is pretty crucial for my app.

Thanks, Frank.
[import]uid: 9044 topic_id: 7837 reply_id: 32977[/import]

Yeah I thought about that before gutting my save game functionality. But then I realized I would only be supporting iOS 4 anyway because of Game Center. [import]uid: 12108 topic_id: 7837 reply_id: 32978[/import]

I’m thinking for older iOS’s that if they get interrupted, they get interrupted and life goes on. Its a lot of work to try and store my entire game state.

As for the other poster, do you really need to measure your app switching in milliseconds? If you could get away with second timing you have the os.time() call. Given how sloppy time wise it is to click the home button, find your other app (or double press home and find it in the running apps list) that millisecond accuracy wouldn’t matter. Its like the old saying:

Measure with a Micrometer. Mark with Chalk. Cut with an Axe.

Do you really need precise measurements when an axe is involved?
[import]uid: 19626 topic_id: 7837 reply_id: 32980[/import]

Yes, I do need the msec timer as it is used for timing sport events that require results in hundreds of a second.

So the os.time() does not give me any useful info.

The user will start the timer from within my app, switch to another app during a race, switch back before the finish and stop the timer from with the app. The time elapsed during the switch is irrelevant, I just need the elapsed time between the starting and stopping of the timer.

-Frank.

[import]uid: 8093 topic_id: 7837 reply_id: 32982[/import]

I’m thinking for older iOS’s that if they get interrupted, they get interrupted and life goes on

y’know that’s a good point. When you’re triaging the problems in your game, I suppose this one is pretty low priority. [import]uid: 12108 topic_id: 7837 reply_id: 32990[/import]

Interesting. Does the new corona also handle a full suspend tho - eg when you get a phone call?

I implemented full game state saving and loading to deal with that. [import]uid: 8872 topic_id: 7837 reply_id: 33013[/import]

Not sure what you mean by “a full suspend.” Do you mean quitting the app? Under iOS 4 it actually takes a fair bit of effort for users to completely quit an app instead of simply suspend it; you have to hit Home twice to see the running apps and then force quit.

I’m planning to do more controlled testing of call interruptions, but I have had people text me while I was playing my game and it all worked fine. [import]uid: 12108 topic_id: 7837 reply_id: 33015[/import]

Previously I found the following behaviour:

App Sleep:

  1. Start game
  2. press home, to switch to another app
  3. Either use fast app switching, OR click the app icon again

RESULT: Game resumed where left off

App Suspend:

  1. Start game
  2. Incoming text, in the popup click to reply to text
    OR
    Incoming call, answer call

RESULT: Game has quit

I’m not sure if this has changed in the new version? [import]uid: 8872 topic_id: 7837 reply_id: 33017[/import]

Look at the plist setting jon said to use, it’s called UIApplicationExitsOnSuspend. [import]uid: 12108 topic_id: 7837 reply_id: 33131[/import]