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

前端 未结 2 1857
野的像风
野的像风 2021-02-04 10:56

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 sea

2条回答
  •  北恋
    北恋 (楼主)
    2021-02-04 11:54

    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

提交回复
热议问题