18. November 2011 16:44
A new feature of Mango (WP 7.5) is fast app switching, a much needed feature, which every developer should implement in their apps. Before mango, every time the application was deactivated the developer had to maintain state and restore it once the application was re activated. That resulted in very slow transitions between apps and a bad user experience. With fast app switching and the WP 7.1 SDK, the phone maintains all state of the app when it is deactivated and when the user activates it again the app starts right away. It is a much better user experience! Windows Phone tries it’s best to maintain the state, but it is not 100% sure that when the user comes back to your app the state will be preserved, so we can check whether the state is still there and if not restore it ourselves.
1: private void Application_Activated(object sender, ActivatedEventArgs e)
3: if (!e.IsApplicationInstancePreserved)
Very easy to do! This is great, but it doesn’t mean we don’t have to implement tomstoning (please note the article refers to WP 7.0, not 7.1), since we still want to maintain a good user experience, we should restore everything as it was even if the phone wasn’t able to persist the state. You can read the article linked above and it’s second part for a great explanation of how to do so.
The question then arises, how do we debug tombstoning if the application is persisted every time we reactivate the app? We have two options:
- Deactivate the app and play around the emulator (or phone) by opening as many apps as you can and pray the phone doesn’t preserve the state when it is reactivated.
- Right click on your project file and go to properties. Navigate to the Debug tab and check the “Tombstone upon deactivation while debugging”.
As you might imagine option 2 is the recommended approach as it is probably a much more efficient way to debug tombstoning! Next time your application is activated e.IsApplicationInstancePreserved will be false.