Reputation: 1
I'm developing a game with Corona and trying to sort out how to handle suspends and resumes. I have some basic questions:
What state data is at risk when an app is suspended? Any and all? Just texture objects?
When I catch an applicationResume event, is there a way to determine whether I need to reconstruct the previous state, or whether the suspend was a brief one (like a call to Facebook) and everything is still intact? Can I just check whether some dedicated variable is nil or still has its expected value?
When I catch the applicationSuspend event, is there a limit to what I can do before I return from the event listener? Will Android or iOS eventually lose patience with an app that is too slow to suspend? In particular, I'm thinking about calls to my server; can I ensure they complete before relinquishing control to the OS?
What exactly does requestExit()
do? Since there is no counterpart in iOS, should I even bother with it in my Android version?
Thanks for your help.
Upvotes: 0
Views: 524
Reputation: 3063
As long as your app does not exit, all state should be saved. On Android, textures will be lost, but will be automatically reconstructed when the app is resumed. You don't have to do that.
You probably should try and pause/cancel any timers or transitions and then resume them when you get back out of safety. If you save things you would normally save to a settings file when you change them, you should not have to save/restore them either.
Yes, there is a limit to what you can do and iOS for certain is impatient. Flush any open files and get out of there. I'm less sure about Android, but it's probably just as impatient.
Yes if you receive a keyEvent for the back button and you're at your main screen, then you should call the native.requestExit() function instead of calling os.exit(). This will assure your apps is shutdown properly instead of just killed.
Rob
Upvotes: 2