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

Can anybody help me out?

Do you mean multitasking? Corona does not support that feature yet.

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

Thanks!

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

1
2
3
4
5
6
7
8
9
settings = {
    iphone =
    {
        plist =
        {
            UIApplicationExitsOnSuspend = false       
        }
    }
}

The game state is kept after switching back ?

@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 :-)

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.

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

Even with this feature we still need to deal with saving for pre iOS 4 devices right?

@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

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.

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.

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?

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.

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.

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.

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.

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?

Look at the plist setting jon said to use, it's called UIApplicationExitsOnSuspend.

Holy cow! How did I miss this feature? Awesome, can't wait to try it!

views:1648 update:2011/10/5 21:23:48
corona forums © 2003-2011