os.exit() not working as expected

Hi all,
For development purposes I have an exit button in my game(which I will remove later).
It executes the following statement:
os.exit()

But…even though the game works as expected and returns to the iPad home screen I notice my game is listed as a suspended game in the suspended game list accessible via a double tap on the home button.
I’m guessing this is just the OS works on the iPad?
Anyone have any info on this?
Thanks,
-Dennis [import]uid: 108253 topic_id: 19669 reply_id: 319669[/import]

I’m having the same problem. I have UIApplicationExitsOnSuspend = false, for the Facebook single login functionality, but I want my app to close for real when the user presses the home button.

I am using os.exit() on the system event ‘ApplicationExits’ but the app stays open (as seen when double tapping).

Any ways to fix this? [import]uid: 70134 topic_id: 19669 reply_id: 76026[/import]

If you have UIApplicationExitsOnSuspend = false, then your app will not quit. It only suspends to the background, and when you start the app again it will continue where it left off.

If you set UIApplicationExitsOnSuspend = true, it will quit. *However* you will still see it in the list when you double tap (iOS4+). Even though it’s in this list, when you start the app again it will initialize from the start.
[import]uid: 70847 topic_id: 19669 reply_id: 76031[/import]

Ingemar’s answer covers this well :slight_smile:

That said, I wanted to add that you should not be using os.exit() - it can cause your app to be rejected by Apple as if it fires it looks like a crash. [import]uid: 52491 topic_id: 19669 reply_id: 76129[/import]

Hmmm… That’s too bad, because I do really need a fix for this. Unfortunately the facebook-single-sign-on requires you to not exit on suspend, so I have the following problem: when you’re playing my game and push the home button to exit you go to the home screen (on iOS).

Then when you push the game icon again you’d expect to be taken to the start screen of the game, as it is in most games, right? But unfortunately you land in the middle of the level you were in when you pushed the home button - and then you need to press the pause button and go to menu first which feels cumbersome to the user.

So what is the proper course to be taken here then? How do I make my app start at the home screen when launching, but still continue from where it was left when resuming, when it actually never exits anymore (so there’s no launches)? [import]uid: 70134 topic_id: 19669 reply_id: 76159[/import]

You can register to receive the suspend and resume events and handle the logic yourself.
[lua]Runtime:addEventListener(“system”, onSystemEvent);[/lua]

Then create a function to handle your logic:
[lua]local function onSystemEvent(event)
local eventType = event.type;

if (eventType == “applicationSuspend”) then
– do something

elseif (eventType == “applicationResume”) then
– restart game
end
end[/lua] [import]uid: 70847 topic_id: 19669 reply_id: 76160[/import]