iOS applicationExit via multi-tasking tray

When a user double-taps the Home button and manually kills a running app, does it still receive “applicationExit” system event?

I ask because I have a tiny piece of code that runs on applicationExit. Check one variable, if true, write one line of data to a file. This works on the simulator with a CMD+R, however on my device, nothing is saved. [import]uid: 38932 topic_id: 25723 reply_id: 325723[/import]

I dont think so…

When you press the Home button once, the app receives an ApplicationSuspend event. Thats it. The app does nothing else unless an ApplicationResume event is received. [import]uid: 64174 topic_id: 25723 reply_id: 103992[/import]

Cheers, as I thought.

I was having a similar problem as ‘Draw Something’ has, where cheating is possible when the app is killed mid-game and then re-launched, but there’s other ways around it.

Thanks for confirming! [import]uid: 38932 topic_id: 25723 reply_id: 103996[/import]

Hi Satheesh,

So when applicationExit is called? I am implementing save and load game data at the moment. I put save data code in applicationExit, it dosen’t work in iPhone simulator but Corona simulator.

If I want to save game state when user kill the app manually or when the app is crashed, what shall I do? [import]uid: 204352 topic_id: 25723 reply_id: 139252[/import]

@xiaotian.tan
Well… all you can do is manually work around the user killing the app

For instance, on an “onApplicationSuspend” event, you can save the game state in a temporary file…
And then “onApplicationResue” delete the temporary file…
Now “onApplicationStart”, check if that temporary file is present… If it is present, it means that the user has manually killed the app. so retrieve the game state from the temporary file and save it in where you originally wanted to save… Make sense?
saving when the app is crashed is a different issue… I am not sure whether the app will fire a “onApplicationExit” when the app crashes… Do check that, but If it does not fire, then I guess you can do a pcall… So any errors will be caught by a listener function… You can give a [lua]os.exit()[/lua] in the listener function which will fire a “onApplicationExit” event… [import]uid: 64174 topic_id: 25723 reply_id: 139255[/import]

If a user kills an iOS app, there is no applicationExit event. This is not a Corona issue but the way iOS works. When your app receives an applicationSuspend event, you must assume that the app will get killed by the OS if it needs the memory and save the state. It will not wake up the app to give it an exit event if it needs to kill it while it’s suspended. You must treat every applicationSuspend as an exit and save the state…

You can record the fact that you received an applicationSuspend and if the app is restarted, the main.lua code will execute and you will get an applicationStart event and you can than check to see if the last event was Exit or Suspend and handle the situation.

Application crash will be the same thing except you won’t get a chance to save any state information. While your app is running you could store some information in a file to indicate the app is running and check it the next time you get an applicationStart event. Saving the state at certain milestones will allow you to track where the app is at in case of a crash or being killed by the user or OS. [import]uid: 7559 topic_id: 25723 reply_id: 139293[/import]

Hi Satheesh,

So when applicationExit is called? I am implementing save and load game data at the moment. I put save data code in applicationExit, it dosen’t work in iPhone simulator but Corona simulator.

If I want to save game state when user kill the app manually or when the app is crashed, what shall I do? [import]uid: 204352 topic_id: 25723 reply_id: 139252[/import]

@xiaotian.tan
Well… all you can do is manually work around the user killing the app

For instance, on an “onApplicationSuspend” event, you can save the game state in a temporary file…
And then “onApplicationResue” delete the temporary file…
Now “onApplicationStart”, check if that temporary file is present… If it is present, it means that the user has manually killed the app. so retrieve the game state from the temporary file and save it in where you originally wanted to save… Make sense?
saving when the app is crashed is a different issue… I am not sure whether the app will fire a “onApplicationExit” when the app crashes… Do check that, but If it does not fire, then I guess you can do a pcall… So any errors will be caught by a listener function… You can give a [lua]os.exit()[/lua] in the listener function which will fire a “onApplicationExit” event… [import]uid: 64174 topic_id: 25723 reply_id: 139255[/import]

If a user kills an iOS app, there is no applicationExit event. This is not a Corona issue but the way iOS works. When your app receives an applicationSuspend event, you must assume that the app will get killed by the OS if it needs the memory and save the state. It will not wake up the app to give it an exit event if it needs to kill it while it’s suspended. You must treat every applicationSuspend as an exit and save the state…

You can record the fact that you received an applicationSuspend and if the app is restarted, the main.lua code will execute and you will get an applicationStart event and you can than check to see if the last event was Exit or Suspend and handle the situation.

Application crash will be the same thing except you won’t get a chance to save any state information. While your app is running you could store some information in a file to indicate the app is running and check it the next time you get an applicationStart event. Saving the state at certain milestones will allow you to track where the app is at in case of a crash or being killed by the user or OS. [import]uid: 7559 topic_id: 25723 reply_id: 139293[/import]