Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I have a windows phone 7 application how do I make sure it supports fast task switching?

What do I need as a developer to be sure my apps support fast task switching?

Ideally, I'm looking for like a developer check list of dos and don'ts.

I did search, but everything I found made me feel like I was missing something, tended to be more marketing instead of developer steps and technical details.

Thanks!

like image 817
Chris Craft Avatar asked Aug 17 '11 21:08

Chris Craft


1 Answers

Most of the work for FAS is handled for you automatically. The main thing to keep in mind is what Tombstoning means to your application. When resuming via FAS, the intent is that you don't have to un-tombstone anything, so there's usually no need to restore view model state, or anything like that. There are a couple of places for which you will need to write code - here's a quick checklist.

PhoneApplicationPage.OnNavigatingFrom - Experiment with the controls you're using to make sure that FAS restores the data that was there for you. For example - the TextBox control correctly remembers everything you had put into it, but the MediaElement doesn't remember the video or where it's playback head was positioned.

PhoneApplicationPage.OnNavigatedTo - Anything that you saved off in OnNavigatingFrom needs to be re-applied here in OnNavigatedTo. For example - reloading the video source into the MediaElement, repositioning the video and starting it back up again.

Application.Activated - The event args for this event now contain a property called IsApplicationInstancePreserved. This property returns TRUE when the application is coming back through FAS, or FALSE when the application is coming back from Tombstoning. So you'd have code something like this:

private void Application_Activated(object sender, ActivatedEventArgs e)
{
    if (!e.IsApplicationInstancePreserved)
    {
        RestoreStateFromTombstone();
    }
}

private void Application_Deactivated(object sender, DeactivatedEventArgs e)
{
    SaveStateForTombstone();
}

That's the essentials. I haven't done any real stress testing yet on the FAS infrastructure to see where it breaks, but this has served me well for the experimenting I've done so far.

For more information, there's a short video from the MIX11 conference called Get Ready for Fast Application Switching presented by Adina Trufinescu that gives more details on FAS which definitely helped me get started.

/chris

like image 115
Chris Koenig Avatar answered Oct 31 '22 00:10

Chris Koenig