I am having a problem with handling system events. It appears that the “applicationExit” event is being called on startup when I run my application in the corona simulator, when it should only be called when the application exits (i.e. I close the corona simulator). I am trying to use the “applicationExit” event to save user data when the application exits, so it is critical that the “applicationExit” event only be called when the application exits. Below is a sample of my code:
--main.lua local function onSystemEvent( event ) if ( event.type == "applicationOpen" ) then if box.exitCount == nil then defaultValues() else setValues() end elseif ( event.type == "applicationExit" ) then --problem: seems to run "applicationExit"" on startup print("application is exiting!!!!!") if box.exitCount == nil then print("first time opened") else box.exitCount = box.exitCount + 1 print( "exitCount = "..box.exitCount) end saveBox() --printBoxValues() elseif (event.type == "applicationSuspend") then --do nothing end end Runtime:addEventListener( "system", onSystemEvent )
When I run my code on the corona simulator, the “application is exiting!!!” text appears in the output for about a second or two and then disappears, indicating that the “applicationExit” event was called on startup when it should only be called when the application exits. Is there a way to prevent the “applicationExit” from running on startup? Any help in addressing this problem would be much appreciated!