1、Launching事件处理
当程序启动时调用,当程序重新激活时不调用
从IsolatedStorage加载一些永久配置数据(persisteddata)
private void Application_Launching(objectsender,LaunchingEventArgs e)
{
Debug.WriteLine(“TOMBSTONE:Application_Launching at {0}”,Datatime.Now.ToLongTimeString());
using(IsolatedStorageFile file =IsolatedStorageFile.GetUserStoreForApplication())
{
if(IsolatedStorageSettings.ApplicationSettings.Contains(IsolatedStorageSetting1))
{
PersistedData= IsolatedStorageSettings.ApplicationSettings[IsolatedStorageSetting1] as string;
}
}
}
2、Closing事件处理
当程序关闭时调用,当程序失去激活时不调用
保存一些永久配置数据(persisteddata)到IsolatedStorage
3、Deactivated事件处理
当程序失去激活时调用,当程序关闭时不调用
使用PhoneApplicationService.State保存一些临时数据(transient data)
4、Activated事件处理
当程序重新激活的时候调用,当程序启动的时候不调用
从PhoneApplicationService.State读取一些临时数据(transientdata)
目的:恢复到用户离开该页面的状态,保持用户体验的一致性
IsolatedStorage和PhoneApplicationService.State中的数据都是以键值对的形式存在,即PersistedDataSetting与PersistedData、TransientDataState与TransientData
复习:
当用户在应用程序首页点击回退按钮的时候,触发Closing事件而不是Deactivated事件
Tombstoned的程序可能永远都不会被重新激活
注意:程序集引用之前必须先Build,不然会报错