“The procedure in which the Operating System terminates an application’s process when the user navigates away from the application. The Operating System maintains state information about the application. If the user navigates back to the application, the Operating System restarts the application process and passes the state data back to the application.”
When your application gets tombstoned, you get an opportunity to save some state about your application… Common questions I get are what should I save, where should I save it and when? Let me try and address some of these questions:
What should I save
Where should I save it
Each page has a State dictionary and their is also an application-wide dictionary as part of the
PhoneApplicationService. These state dictionaries get automatically persisted when tombstoned! The helper class will save each control that you give to it on the page specific dictionary, and it will use the control's name as the key!
When should I save it
The last question is when? You have two options here… Application lifecycle events (
Application_Deactivated), or on a page level, you can override
Since the helper class really tries and addresses page specific state, it makes sense that we will be using
Let's try it out…
The helpers are implemented as extension methods so all you have to do is:
public partial class NormalPage : PhoneApplicationPage
protected override void OnNavigatedFrom(
protected override void OnNavigatedTo(
Easy, isn’t it!
Here is the sample application.
Read more about the Windows Phone execution model here: