When an app transitions from being tombstoned or dormant back to the running state, the PhoneApplicationService.Activated
event is raised. This provides an opportunity to restore the transient and persistent state of the app.
Note
Restoring the transient state of a PhoneApplicationPage
should be performed in its OnNavigatedTo
method, as you see later in the chapter.
Restoring the transient state involves taking the user to the point where she was when the Deactivated
event occurred, and may involve restoring the positions of UI elements, repopulating viewmodel properties, and so on. The goal is to provide the user with a seamless experience, and to emulate a multiple application environment, in which the application appears as though it was left running in the background.
The following code demonstrates handling of the PhoneApplicationService.Activated
event, to restore transient and persistent state:
void Application_Activated(object sender, ActivatedEventArgs e)
{
/* Restore persistent state like so: */
someObject = IsolatedStorageSettings.ApplicationSettings["Key"];
/* Restore transient state like so: */
DataContract = PhoneApplicationService.Current.State["DataContractKey"];
}
3.144.9.124