• Advertisement
Sign in to follow this  

Why does my game restart when I minimize and reopen it?

This topic is 1404 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I haven't found much of anything to help me solve this problem, and debugging it is a pain because it doesn't happen when debugging remotely.  Let's say I pressed the home button and minimize the app.  applicationDidEnterBackground gets called, yes.  Is this where I'm supposed to save all of my game data and write it to the app's private data directory and load it when it comes back to the foreground?  All of my game's information is stored in a series of linked lists, and saving it would be easy enough I guess.

 

Another thing, does all of the app's memory get deallocated when it's minimized?  Should I deallocate everything to avoid memory leaks?  I find iOS not to be very straightforward in this regard.  Any advice is appreciated.  Thanks.

 

Shogun.

Share this post


Link to post
Share on other sites
Advertisement

When the app enters the background you should save state because the user may close the app by double tapping the home button and swiping up.

Share this post


Link to post
Share on other sites

A long time ago, before iOS's 'multitasking', games would often save the entire game state on a suspend event, so that when the app is reopened you can restore the player to the exact position, be it mid-level, deep in the front end menus, or whatever.

 

These days, for most titles, it's not worth the effort. Just save any user progress as soon as it occurs, if the user suspends your app and tries to return to it, usually the OS will restore your app to the foreground as if nothing has happened. In the event that the OS decided to kill your app to reclaim the RAM, or the user manually killed your app, it doesn't matter much because you will have saved the progress fairly recently.

 

The only thing I would normally bother doing is to pause the game. One exception is that if your game is pushing the device's memory usage to the limit, then you should make an effort to free a decent chunk of memory on suspend (textures are quite easy to remove/reload), otherwise, the OS is very likely to close your app (particularly bad if your app has links to safari or the app store or something, the user follows the link from within your game, returns to the game only to find it has crashed!).

 

Here's the relevant doc from Apple: https://developer.apple.com/library/ios/documentation/iphone/conceptual/iphoneosprogrammingguide/ManagingYourApplicationsFlow/ManagingYourApplicationsFlow.html

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement