The Windows Phone RTM operating system had only one active application and when application were sent to the background the state was serialized and kept in the application’s isolated storage. This process called tombstoning and application in such state called tombstoned. When user return to the tombstoned application, he would have to wait a while as the application deserialized its state and recovered and we as developers had to take care about saving the application’s state and resuming it.
With Mango that is no longer the case: there is only one active (foreground) application, but once an application is sent to the background the operating system keeps its image alive in memory for as long as possible without impairing the performance of the currently active application. This new state of the application called dormant. When user reactivate the dormant application, the experience would be virtually instantaneous as restoring the application’s in-memory image is a fast operation. In case the dormant application’s memory need to be released to ensure active application performance doesn’t hurt, Mango will tombstone the dormant application and user will have to wait to get back to the application as it was in RTM. This new mechanism is called Fast Application Switching (FAS).
This (short) post shows how to be aware of the manner in which your application was restored after being deactivated. When application is activated, ActivatedEventArgs has new property IsApplicationInstancePreserved which indicates the latest state of resumed application. If IsApplicationInstancePreserved is true this means, that all application memory is intact and virtually nothing should be done in such case. If IsApplicationInstancePreserved is false then we need to take care of “old-styled” tombstoning resume:
private void Application_Activated(object sender, ActivatedEventArgs e)
// Ensure that application state is restored appropriately
WasTombstoned = true;
//Your code to resume from tombstoning
WasTombstoned = false;
That’s almost it. The default behavior of the Mango application lifecycle manager is to preserve application images in memory as long as possible and the tombstoning process will occur automatically by phone’s operation system when it really needed. But how to check/debug resuming from tombstoning this process with emulator when it has only one application running?
The new version of developer tools allow us to force an application to forego FAS in favor of tombstoning. To force tombstoning, open project’s properties and navigate to the “Debug” tab:
Ticking the checkbox that says “Tombstone upon deactivation while debugging” will force your application consistently perform tombstoning upon deactivation while the debugger is attached. Clear the checkbox to have the application use FAS again.
Stay tuned to part 7 – Silverlight & XNA interoperability