The execution model of Windows Phone
is designed to make the phone as responsive as possible and to maximize
the battery life of the device. One way that this is achieved is by
limiting the phone to a single running application. Multiple
applications running in the background risk slowing the foreground
application and may tie up the processor and cause the phone to consume
more power.
Note
While the phone’s execution model is limited
to a single app being in execution at any time, Windows Phone allows
the use of background tasks, which run periodically and are independent
of your foreground app.
In addition to greater responsiveness and
extended battery life, the execution model provides users with a
consistent navigation experience between applications. On Windows
Phone, users are able to launch applications from the App List screen
or from a tile on the Start Experience. The hardware Back button allows
users to navigate backward, through the pages of a running application
or through the stack of previously running applications.
The goal of transient state
preservation and restoration is to provide the user with a simulated
multiple application experience, where it seems to the user that your
application was left running in the background, even though it may have
been terminated by the operating system.
1. Application State
There are two types of application state:
persistent and transient. Persistent state exists when an application
launches. It is saved to a private storage area called isolated storage
and may include data such as configurable settings or files.
Transient state is discarded when an application is closed. It is stored at the application level in the Microsoft.Phone.Shell.PhoneApplicationService.State
dictionary or at the page level in the PhoneApplicationPage.State
dictionary.
There is a single PhoneApplicationService
instance for the entire app, and its state dictionary should be used
only by objects running in the context of the application as a whole. A
unique state dictionary is created for each page in your app, and you
should use it rather than the PhoneApplicationService.State
dictionary whenever possible.
Note
The PhoneApplicationPage.State
dictionary is accessible only during or after the OnNavigatedTo
method is called, or during or before the OnNavigatedFrom
method is called. If you attempt to access it too early or too late an exception is raised.
The PhoneApplicationPage.State
dictionary is limited to 2MB for each page and 4MB for the entire app.
You should, therefore, not use it for storing a large amount of data.
Transient state may include results from web service calls or data from partially completed forms (see Figure 1).
FIGURE 1 Persistent state and transient state storage locations.