Thanks for visiting my blog!
Yes.
Ok, maybe I can’t leave it at that. As Windows Phone 7 users upgrade to Mango, they probably want a Mango (e.g. Windows Phone OS 7.1) version of your application. Don’t disappoint them. This doesn’t mean you should completely retool your application for Mango. But if I am suggesting that you don’t spend a lot of time on the new app, then why create one to begin with? Fast Task Switching.
Fast Task Switching
Fast Task Switching in Mango allows users to more easily leave and return to your application. What this effectively means is that users will be able to switch away from your app and return to without tombstoning in most situations. If a user leaves your app then wants to return to it, in Windows Phone OS 7.0, you had to save state when the user left and re-hydrate it when they returned – usually resulting in a short delay for the user. In Windows Phone OS 7.1, the operating system will suspend your process when the user leaves your app. You still need to save the tombstoning state, but when your application is restarted, the operating system will tell you whether you need to re-hydrate the tombstone data. This means that in many cases, returning to your application should be almost instantaneous.
So, how do you know? In Windows Phone OS 7.0, you would be given an opportunity to rehydrate your application during the application’s Activate event like so:
private void Application_Activated(object sender, ActivatedEventArgs e)
{
var state = PhoneApplicationService.Current.State;
if (state.ContainsKey("SelectedPivotIndex"))
{
this.currentPivotIndex = (int)state["SelectedPivotIndex"];
}
}
By storing the state in the PhoneApplicationState class, this data will be tombstoned for you. This doesn’t’ change in Windows Phone OS 7.1, but you are giving information in the Activated event to tell if you need to load the state from tombstone data:
private void Application_Activated(object sender, ActivatedEventArgs e)
{
if (!e.IsApplicationInstancePreserved)
{
var state = PhoneApplicationService.Current.State;
if (state.ContainsKey("SelectedPivotIndex"))
{
this.currentPivotIndex = (int)state["SelectedPivotIndex"];
}
}
}
By using the new IsApplicationInstancePreserved property of the ActivatedEventArgs class you can determine if you need to de-tombstone. If the Application’s process was preserved (which will happen a majority of the time), you can simply ignore tombstoning as all memory was preserved from when it was deactivated.
At a minimum, you should add this simple check and publish a Mango version of your app. It will make your users much happier.