Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Fast App Switching
Started by lhvio89 Mar 14 2011 05:18 AM

- - - - -
20 replies to this topic
[TOPIC CONTROLS]
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

lhvio89

[GLOBAL: userInfoPane.html]
lhvio89
  • Enthusiast

  • 64 posts
  • Corona SDK

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
uid: 44896 topic_id: 7837 reply_id: 307837


[TOPIC: post.html]
#2

lhvio89

[GLOBAL: userInfoPane.html]
lhvio89
  • Enthusiast

  • 64 posts
  • Corona SDK

Can anybody help me out?
uid: 44896 topic_id: 7837 reply_id: 27988


[TOPIC: post.html]
#3

BioHazard-Media

[GLOBAL: userInfoPane.html]
BioHazard-Media
  • Contributor

  • 104 posts
  • Corona SDK

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


[TOPIC: post.html]
#4

lhvio89

[GLOBAL: userInfoPane.html]
lhvio89
  • Enthusiast

  • 64 posts
  • Corona SDK

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

Thanks!
uid: 44896 topic_id: 7837 reply_id: 28021


[TOPIC: post.html]
#5

jonathanbeebe

[GLOBAL: userInfoPane.html]
jonathanbeebe
  • Contributor

  • 654 posts
  • Alumni

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]
uid: 52430 topic_id: 7837 reply_id: 32379


[TOPIC: post.html]
#6

yuewah

[GLOBAL: userInfoPane.html]
yuewah
  • Contributor

  • 125 posts
  • Guests

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


[TOPIC: post.html]
#7

jonathanbeebe

[GLOBAL: userInfoPane.html]
jonathanbeebe
  • Contributor

  • 654 posts
  • Alumni

@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 :-)
uid: 52430 topic_id: 7837 reply_id: 32399


[TOPIC: post.html]
#8

jhocking

[GLOBAL: userInfoPane.html]
jhocking
  • Corona Geek

  • 1,223 posts
  • Guests

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.
uid: 12108 topic_id: 7837 reply_id: 32684


[TOPIC: post.html]
#9

J. A. Whye

[GLOBAL: userInfoPane.html]
J. A. Whye
  • Corona Geek

  • 1,689 posts
  • Corona SDK

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
uid: 9440 topic_id: 7837 reply_id: 32743


[TOPIC: post.html]
#10

Omnigeek Media

[GLOBAL: userInfoPane.html]
Omnigeek Media
  • Corona Geek

  • 2,975 posts
  • Corona SDK

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


[TOPIC: post.html]
#11

jonathanbeebe

[GLOBAL: userInfoPane.html]
jonathanbeebe
  • Contributor

  • 654 posts
  • Alumni

@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
uid: 52430 topic_id: 7837 reply_id: 32970


[TOPIC: post.html]
#12

corona3

[GLOBAL: userInfoPane.html]
corona3
  • Observer

  • 1 posts
  • Guests

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.
uid: 9044 topic_id: 7837 reply_id: 32977


[TOPIC: post.html]
#13

jhocking

[GLOBAL: userInfoPane.html]
jhocking
  • Corona Geek

  • 1,223 posts
  • Guests

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.
uid: 12108 topic_id: 7837 reply_id: 32978


[TOPIC: post.html]
#14

Omnigeek Media

[GLOBAL: userInfoPane.html]
Omnigeek Media
  • Corona Geek

  • 2,975 posts
  • Corona SDK

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?
uid: 19626 topic_id: 7837 reply_id: 32980


[TOPIC: post.html]
#15

FrankS

[GLOBAL: userInfoPane.html]
FrankS
  • Contributor

  • 219 posts
  • Corona SDK

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.

uid: 8093 topic_id: 7837 reply_id: 32982


[TOPIC: post.html]
#16

jhocking

[GLOBAL: userInfoPane.html]
jhocking
  • Corona Geek

  • 1,223 posts
  • Guests

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.
uid: 12108 topic_id: 7837 reply_id: 32990


[TOPIC: post.html]
#17

kam187

[GLOBAL: userInfoPane.html]
kam187
  • Contributor

  • 455 posts
  • Corona SDK

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.
uid: 8872 topic_id: 7837 reply_id: 33013


[TOPIC: post.html]
#18

jhocking

[GLOBAL: userInfoPane.html]
jhocking
  • Corona Geek

  • 1,223 posts
  • Guests

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.
uid: 12108 topic_id: 7837 reply_id: 33015


[TOPIC: post.html]
#19

kam187

[GLOBAL: userInfoPane.html]
kam187
  • Contributor

  • 455 posts
  • Corona SDK

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?
uid: 8872 topic_id: 7837 reply_id: 33017


[TOPIC: post.html]
#20

jhocking

[GLOBAL: userInfoPane.html]
jhocking
  • Corona Geek

  • 1,223 posts
  • Guests

Look at the plist setting jon said to use, it's called UIApplicationExitsOnSuspend.
uid: 12108 topic_id: 7837 reply_id: 33131


[TOPIC: post.html]
#21

BeyondtheTech

[GLOBAL: userInfoPane.html]
BeyondtheTech
  • Contributor

  • 477 posts
  • Corona SDK

Holy cow! How did I miss this feature? Awesome, can't wait to try it!
uid: 6084 topic_id: 7837 reply_id: 40333



[topic_controls]
[/topic_controls]