2014-03-07 98 views
-4

我要上了Windows Phone 8 app.how維持會話上維持會話做我保持用戶會話我怎麼了Windows Phone 8

+1

請張貼有你想要什麼指示的具體問題,是什麼你試過了,什麼不適合你。 –

+0

想要維護像我們在ASP.NET中使用的用戶會話來跟蹤用戶信息。 – Kanniyappan

+0

你曾經使用桌面或移動應用程序嗎?它們在處理數據的方式上與Web應用程序不同。通常,您的移動應用程序中只有一個用戶,其後面有文件系統/獨立存儲。這是你需要的嗎? –

回答

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) 
{ 
} 

也看到這個圖,從微軟從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); 
}