by brad
16. September 2010 06:00
Windows Phone 7 applications deal with two distinct kinds of local data: data that belongs to the application (e.g. settings, local data storage) and data that belongs to an specific use or session of an application (e.g. page state, cached web queries). The first kind of data is called persistent data and the second is referred to as transient state.
Persistent Data
Persistent data belongs to the application on a specific phone and is stored in isolated storage. Every time the application is run on the phone, it accesses the same persistent data. Persistent data can be saved when the application closes or is deactivated or it can be saved as the user navigates through the application. In my Gas Mileage application, the gas mileage notebook entries are an example of persistent data. A more common example is application settings.
Transient State
Transient state is data that only has value for a specific run or instance of an application. When the application is exited by the user, this data can be safely thrown away. However, if the application was not actively exited by the user, but was instead replaced by another application, an incoming phone call, or a launcher/chooser, then transient state must be stored safely away so it can be brought back when the application is activated again. Transient state is stored in the PhoneApplicationService.State property.
An example of transient state might be values inputted into a form, the selected value in a list, or some cached data retrieved from a web service call. As a developer, you can write code to save this data off when your application is deactivated and read this data to restore the app to its expected state when the application is activated.
Summary
| | Scope | Storage | Read/Write |
| Persistent Data | Application on single phone | Isolated Storage | App opened / closed, or as the app runs |
| Transient State | Application session | PhoneApplicationService State Property | App deactivated / activated |
Other Resources
More Tips