Guides for Windows
Jan 5th, 2013, 7:05 pm
One of the key features in Mango is Fast Application Switching.

This is a radical change to the life-cycle of applications, and one of the very first things you’ll want to do, when upgrading your Windows 7 application to Mango will be to support Fast Application Switching.

Here’s the deal. In Windows 7, if your application was running and the user started a second application (e.g., by pressing the Windows key or taking a call) your application was immediately tombstoned. When the user returned to your application (using the back key) you would restore state from isolated storage. That can be a bit time consuming.

In Mango, when your application is running and the user starts a second application you are not tombstoned, you are put into a Dormant state where your image is maintained. (Note, the application is stopped and disconnected, so you still have to restore sockets, update timers, etc.)

Key to making all this work is knowing whether you are being restored from being Dormant or from having been Tombstoned. That turns out to be wicked easy. Here’s an incredibly simple program that illustrates how it is done, and how you can test it.

Create a new Windows Phone 7.1 application. Put a single, centered TextBlock named Message with no text. That is your UI.

Open App.xaml and create a static property to hold the status,
1| public static bool WasTombstoned { get; private set; }

Locate the Application_Activated method in App.xaml and add this test:
1| private void Application_Activated(
2| object sender,
3| ActivatedEventArgs e )
4| {
5| WasTombstoned = ! e.IsApplicationInstancePreserved;
6| }


Note the inversion: you were tombstoned if IsApplicationInstancePreserved is false.

Finally, we’ll indicate how we were restored by setting the Message TextBlock you created in MainPage.xaml.
1| public MainPage()
2| {
3| InitializeComponent();
4| Message.Text = App.WasTombstoned ? "Restoring..." : "Fast!";
5| }


Running this you should see that you are typically coming back from a Dormant state using Fast Application Switching. To make sure it is working, however, you’ll want to force tombstoning. Easily done: right click on the project in Visual Studio, and choose Properties. Click on the Debug tab and tick the CheckBox that says Tombstone upon deactivation while debugging. Try the application again and this time you should see Restoring….
Jan 5th, 2013, 7:05 pm

!~! Retired !~!
MOBILISM.ORG
SUPPORT DEVELOPERS. IF YOU LIKE IT, BUY IT. ◄