Game Development Community

How to handle multi tasking on iPhone 4 etc?

by Warthog · in iTorque 2D · 11/29/2010 (2:43 pm) · 7 replies

Hi all,

I have been developing to an iPhone 3G and since it doesn't allow multi tasking of apps I had no idea that my app is messed up on the newer phones. I borrowed an iPhone 4 and found that when that pressing the main button doesn't quit an app. The problem I'm having is that when someone brings my app back to the front after doing this, the app is not working.

Is there a procedure for handling this? In the script, what should I be doing to suspend and resume the app?

Thanks.

#1
11/30/2010 (12:40 am)
Okay, a little more time with an iPhone 4 and I can say that when the big button gets pressed and my app goes to the "background" that my endGame stuff never gets run. Which means the game never gets saved and can't be resumed on the next startup. So my most requested feature doesn't work on the new iDevices.

I did discover though that when the user brings my app back to the foreground it does restart the app.

How should this whole multitasking thing be handled in iTGB?

Anyone?

#2
11/30/2010 (12:49 am)
Take a look at Robert's implementation - it worked well for me
#3
12/01/2010 (1:14 am)
So does that take care of everything and I don't need to add anything in script? Cool!

One thing I don't understand is, on old iDevices the home button quits the game. On the new devices the home button simply moves the app to the background. When you quit an app that is in the background, does anything get sent to the app so it can do things like saving the game, and can it do that while it is in the background state.

Do I need to add a quit button now?
#4
12/01/2010 (10:27 pm)
Backgrounding simply means "prepare to quit anyway, but store state". The OS handles quitting for you.

Note that the linked implementation calls some script functions, oniPhoneResignActive() etc. That is where you put your save calls.
#5
12/02/2010 (12:34 am)
Thanks, seems simple enough, after adding Robert's Implementation, I would need to execute my save game code from oniPhoneResignActive() just incase they quit rather than return my game to the foreground? Cool, easy.

Any idea if Robert's Implementation will work in iTGB 1.2? I have an old game that I really should fix too, but I can't update to 1.4 because of the writing to disk bugs in 1.4.

Easy fix in the two upcoming games though.

Thanks to everyone for the help!
#6
12/02/2010 (3:09 am)
looking forward to what you create :)
#7
12/02/2010 (8:15 am)
I think it should be easy enough to make it work in iT2D 1.2, if you have that engine already compiling against the 4.x SDKs.