I had some questions of my own regarding post-suspend and post-exit cleanup needs of my app so I wrote a little test app that does nothing but alert me (on console) when these states occur. I had some interesting observations & questions which in some cases don't make sense. I'd like to open this up for some discussion to see what you all think. Here goes :
1) for IOS we can specify UIApplicationExitsOnSuspend = true in build settings. Is there an Android equivalent if we want this behavior consistent on both platforms?
2) With UIApplicationExitsOnSuspend = true my demo app sure enough exits when I click home button. However, when hit the power button on my IOS device the demo app does not exit but instead goes into suspended mode.
3) Very similar to the case above, if I let the app run on foreground and do nothing, eventually my IOS device goes into powersave mode and shuts screen down and sleeps. Again my app does not exit but goes into suspend mode. When I hit home or power to wake the device up my app resumes from suspend state.
So #2 & #3 proves that checking for ApplicationExit state and doing things like closing db etc might be of little use if you can't even force your app to exit on suspension UIApplicationExitsOnSuspend = true may lead you to believe. Developer beware!
4) Using either UIApplicationExitsOnSuspend = true or false states another potential pitfall is when a user kills your app. I placed my app in suspended state and then double clicked the Home button. Using the new IOS7 gesture of flicking the app upwards, I forced my app to stop running. I would have expected to see Application Exit event firing off first but sadly this was not the case. So once again if your app needs to take care of business before exiting you will miss the boat when your user gives your app the flick.
5) I observed a very similar outcome on Android. Using Settings / Applications / Manage Applications - I was able to "Force Stop" my app to see which application state messages I would get. Unsurprisingly I got none. Same comment as above. Perhaps you need to do the cleanup (if its crucial) at suspend rather than wait for exit which may never come...
I would very much welcome thoughts and feedback on how you cope with the lack of an authoritative Exit state on IOS & Android platforms when using the Corona SDK. Many thanks in advance.
Code snippet used to get application state info printed on console included below :
local function onSystemEvent( event ) if (event.type == "applicationStart") then print("Application started") elseif (event.type == "applicationExit") then print("Application exited") elseif ( event.type == "applicationSuspend" ) then print("Application suspended") elseif event.type == "applicationResume" then print("Application resumed from suspension") end end --setup the system listener to catch applicationExit etc Runtime:addEventListener( "system", onSystemEvent )