顯示具有 SuspensionManager 標籤的文章。 顯示所有文章
顯示具有 SuspensionManager 標籤的文章。 顯示所有文章

2014/12/16

[筆記] Windows Store App 使用 SuspensionManager 無法儲存頁面狀態的問題

其實在開發 Store App 時如果新增的頁面是 BasicPage.xaml 以上的頁面,就會自動在方案下面開一個 common 目錄,並放一些預設的 Helper 來協助快速開發 App, 其中 SuspensionManager.cs 就是用來提供儲存狀態的 Helper Class



然後按照: Saving and Restoring State in a Windows 8 XAML App 提供的操作方式


1.在 App 的 OnLaunched 加入
 SuspensionManager.RegisterFrame(rootFrame, "AppFrame");

2.在 App 的 OnSuspending 加入
 await SuspensionManager.SaveAsync();
記得 OnSuspending  要 async 

3.在 App 中的 OnLaunched 判斷
if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
{
 await SuspensionManager.RestoreAsync();
}


就可以實作出暫停/回復狀態的 App 了