WP7: Upgrading Your App From 7.0 to Mango (FAS / Tombstoning)

28 August 2011

While upgrading an existing Windows Phone 7.0 application to Mango and all its multitasking and performance improvement glory is a pretty easy task (simply go to the Project properties and change the target from Windows Phone 7.0 to Windows Phone 7.1), there are a few things you need to watch out for when upgrading that you might have to fix manually.

One of the bugs I came across in Noborizaka was that when my application was first launched, everything would operate as normal - but whereas in the old Windows 7.0 version if my application got tombstoned and reactivated everything would work fine, in Mango, after my app was rehydrated, the databinding for my listboxes etc. didn't seem to be valid any more so new items wouldn't appear on the main page until I reset the application fully.

It turns out the reason for this is that as part of Mango and Fast Application Switching (FAS), the OS automatically stores your application's entire state while it's in the "multitasking backstack". So therefore, you need to check the .IsApplicationInstancePreserved proeprty in the Application_Activated of your App.xaml.cs, and if it's true, you should not restore your state from IsolatedStorage. Example:

//Windows Phone 7.0
private void Application_Activated(object sender, ActivatedEventArgs e)
{
    RestoreStateFromTombstone();
}

//Windows Phone 7.1/7.5/Mango
private void Application_Activated(object sender, ActivatedEventArgs e)
{
    if (!e.IsApplicationInstancePreserved)
    {
        RestoreStateFromTombstone();
    }
}

Everything else should work as normal - good luck to all the devs out there making Mango apps! (p.s. if you'd like to read more on the Execution Model of WP7, and what the lifecycle of an application looks like, you can take a look at the MSDN documentation here.)

Tags: FAS, Mango, Tombstoning, wp7

Add a Comment

No Comments