我如何在Windows Phone 8上维护会话

时间:2014-03-07 11:17:49

标签: windows-phone-8

我想在Windows Phone 8 app上维护会话。我是否维持用户会话

1 个答案:

答案 0 :(得分:0)

在WP8中,有些事件会在应用程序启动,关闭,激活或停用时触发。这些事件处理程序可以在Wp8应用程序的App.xaml.cs文件中看到。

// Code to execute when the application is launching (eg, from Start)
// This code will not execute when the application is reactivated
private void Application_Launching(object sender, LaunchingEventArgs e)
{
}

// Code to execute when the application is activated (brought to foreground)
// This code will not execute when the application is first launched
private void Application_Activated(object sender, ActivatedEventArgs e)
{
}

// Code to execute when the application is deactivated (sent to background)
// This code will not execute when the application is closing
private void Application_Deactivated(object sender, DeactivatedEventArgs e)
{
}

// Code to execute when the application is closing (eg, user hit Back)
// This code will not execute when the application is deactivated
private void Application_Closing(object sender, ClosingEventArgs e)
{
}

另请参阅从Microsoft this pdf获得的此图表:

Windows Phone 8 Application Life cycle

因此,要做的就是放置适当的代码,用于保存和从应用程序的独立存储中检索数据。一个例子可能是以下代码读取存储的xml文件:

XElement doc;
using (var isoStoreStream = new IsolatedStorageFileStream("TimeSpaceData.xml", FileMode.Open, isoStoreFile))
{
    doc = XElement.Load(isoStoreStream);
}

return doc;

以下代码将保存xml文件:

XElement pDoc = GetXElementYouWantToSave();
using (var isoStoreStream = new IsolatedStorageFileStream("TimeSpaceData.xml", FileMode.Create, isoStoreFile))
{
    pDoc.Save(isoStoreStream);
}