Overview
-
When leaving an app in Windows Phone, it is either 'Deactivated' or 'Closed',
-
Closing actually exits the app and gives back all memory, whereas Deactivating suspends the app, retaining some state in memory
-
Deactivating occurs,
- when you push the Home button or when the app is interrupted e.g. by a phone call
-
Closing occurs,
-
when you reach the home screen hub of the app and push the back button again
-
Closing also occurs if an app was deactivated, tombstoned and then 5 more apps were tombstoned after it (see below)
-
A deactivated app has all of its state saved until the phone needs the memory at which point the app is 'Tombstoned'
-
A tombstoned app only saves the navigation state and whatever was stored in the global
State
dictionary
-
Only a maximum of five apps can be tombstoned at a time. Any more than that and the oldest app is closed (and the State dictionary/Navigation state is lost)
-
Hold down the back button on your phone to see a list of tombstoned/deactivated apps
Preserving state
-
The App.xaml.cs code-behind file feature four methods for Lifecycle management,
-
Launching
occurs when a new app instance is created
-
Closing
occurs when then app instance is destroyed
-
Activated
occurs when the app returns from tombstoning or deactivation
-
Deactivated
occurs when the app is interrupted
-
The general rule is to assume that the app will be tombstoned when
Deactivated
and so relevant state should be saved to the
State
dictionary here
-
On activation should assume that tombstoning occurred and check the
State
dictionary for saved values
-
In
Closing
unsaved data such as half filled forms is (and should be) lost so do not save this kind of information to persistent storage unless you have good reason