Coronasdk development tip – suspend

In hopes to save someone else a few hours of reading and digging I figured I would start posting some quick tips about some of the small things that will make your programming experience on iOS with coronasdk a little easier and let’s face it, make you feel more awesome that your applications does what it’s supposed to do when a user interacts with it. 

If the user hits the home button on iOS the app closes and if they where in the middle of doing something, by default they will not be returned to that state in the app. Not sure why this is the default functionality but none the less I started searching on how to “save state” of the app when it’s interrupted by navigating to another application or clicking the home button to get back to the main screen. 

If you do some googling as I did for “saving state”, or “coronasdk suspend” and so forth you will more than likely come across a few posts that suggest listening for and event that the applications is exiting and then figuring out a way to save the state of all the variables and logic needed to load the screen the user is on when they return to the app. This is totally the case and something you should do if you want to return them to that state if the app quit but suspend is different that quitting or exiting the app all together. 

If you want the app to suspend and return to the screen and state that it’s in when the user navigates away and returns via “iOS multitasking” then the solution is very simple. Go into your app build.settings file and add the following line “UIApplicationExitsOnSuspend = false”. By default a corona app “Exits” the app when suspended by default. You are basically telling the app to suspend rather than exit by adding this to your build settings.