Windows Phone 数据的保存和恢复

 // 应用程序启动(例如,从“开始”菜单启动)时执行的代码
        // 此代码在重新激活应用程序时不执行
        private void Application_Launching(object sender, LaunchingEventArgs e)
        {
            Appdata = "进入的时间载入";
        }

        // 激活应用程序(置于前台)时执行的代码
        // 此代码在首次启动应用程序时不执行
        private void Application_Activated(object sender, ActivatedEventArgs e)
        {
            if (e.IsApplicationInstancePreserved)
            {
                return;
            }

            if (PhoneApplicationService.Current.State.ContainsKey("data"))
            {
                Appdata = PhoneApplicationService.Current.State["data"] as string + "重新启动";
            }
        }

        // 停用应用程序(发送到后台)时执行的代码
        // 此代码在应用程序关闭时不执行
        private void Application_Deactivated(object sender, DeactivatedEventArgs e)
        {
            if (!string.IsNullOrEmpty(Appdata))
            {
                PhoneApplicationService.Current.State["data"] = Appdata;
            }
        }

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章