I have a settings save method I call, but I tried unload, and lost focus the application will close out and not save before ever getting to either of those methods. When should I save application settings to keep this from happening?
Should I use a timer and save every 30 seconds, or what?
End of support means experiences with Xbox related features will have limited to no functionality. In addition, earning achievements through Windows Phone devices will be turned off starting May 16, 2022.
How often you save depends on your app. However, the key timings are:
Launching
is called when the app is first launched from the main screen and Closing
is called when the user presses the back key to exit your app. Naturally, you'll most likely want to save permanent data in the Closing
event.
Activated
is called when the user has closed your app via the Windows
button and has gone back into it by pressing the back button. This doesn't get called if the user launches the app for the first time.
Likewise, the Deactivated
event is called when the user presses the Windows
button. Depending on your app, you'll want to save transient data at this point so that when it's restored, you can give the illusion that your app wasn't closed at all. (Otherwise, for example, all textboxes will become empty even if the user entered data before pressing the Windows
button).
Those are the main events, so you can design your app around that. One thing to remember is that if your save files are going to be big, and they take longer than 10 seconds
to save after the closing
event is called, your app will be terminated immediately, possible corrupting the save file. Therefore, for large saves files, you should plan ahead by saving incrementally (for example, after the user has made a change that should remain permanent).
There's no one size fits all
solution to this as saving timings are highly dependant on the type of app being developed. Have a read of the Execution Model MSDN Page as it goes into more detail and provides code examples.
Here is a sample from MSDN on how to implement settings page for Windows Phone.
http://msdn.microsoft.com/en-us/library/ff769510(v=vs.92).aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With