Windwos phone app life cycle you can refer to the MSDN introduction, which is described in detail. Http://msdn.microsoft.com/zhcn/library/windows/apps/xaml/hh464925.aspx
Next, we'll focus on saving the data when the application hangs.
We can save the data by following these three ways.
1, through the Suspensionmanager class
2, through the Navigationhelper class
3, through the api,applicationdata.current.localsettings provided by Microsoft
Note: Suspensionmanager and Navigationhelper are the two classes that Microsoft has packaged for us, right-click Solution, add New Item--basic page, and after adding the basic page vs will automatically generate a common folder.
1. Use Suspensionmanager to maintain the state of the application when it hangs
①, first find App.xaml.cs file
②, registering in the Onlaunched event Suspensionmanager
// notify to save data when registering Suspensionmanager program hangs " Appframe ");
③, saving pending data in event onsuspending
await Suspensionmanager.saveasync ();
④, loading state in onlaunched event
if (E.previousexecutionstate = = applicationexecutionstate.terminated) { // TODO: Loading state from a previously suspended application await Suspensionmanager.restoreasync (); }
2, the use of Navigationhelper class to rely on Suspensionmanager, before using the Navigationhelper class to configure the Suspensionmanager, method as above
①, application hangs save data, in Navigationhelper_savestate
Private void Navigationhelper_savestate (object sender, Savestateeventargs e) { e.pagestate.add (" txt", txtName.Text); }
②, loading and saving data in the Navigationhelper_loadstate event
Private void Navigationhelper_loadstate (object sender, Loadstateeventargs e) { if (E. pagestate!=null&&e.pagestate.containskey ("txt")) { = e.pagestate["txt"asstring; } }
3. Using Microsoft to provide API
// save data Windows.storage.applicationdata.current.localsettings.values[ txt ] = txtName.Text;
// Get Data string str = windows.storage.applicationdata.current.localsettings.values["txt" asstring; if NULL ) { = str; }
Windows Phone app life cycle and data retention