Tore Lervik

Windows Phone 8 - Fast app resume

In Windows Phone 8 you can make your app resume instead of re-launching when you click on the app tile. This will also preserve the backstack of the application.

Fast app resume makes app behave more like they do in Windows 8 when clicking on the app tile. In this example we are resuming the app to where we left it.

WMAppManifest.xml

To start you have to open WMAppManifest.xml by right clicking and choose view code. Then you have to add ActivationPolicy="Resume" to the DefaultTask.

<DefaultTask Name="_default" NavigationPage="MainPage.xaml" ActivationPolicy="Resume" />

App.xaml.cs

Now we need to cancel the navigation to MainPage.xaml when the user clicks the app tile. We do this in App.xaml.cs file. (Note: The sdk doesn't work the way the documentation describes, so my approach is a bit different)

First add private bool reset; to the App class. You should have a method called InitializePhoneApplication that initializes the RootFrame. Add the following:

RootFrame.Navigating += RootFrame_Navigating;
RootFrame.Navigated += RootFrame_Navigated;

Then add the methods needed for canceling the MainPage navigation.

void RootFrame_Navigating(object sender, NavigatingCancelEventArgs e)
{
    if (reset && e.IsCancelable && e.Uri.OriginalString == "/MainPage.xaml")
    {
        e.Cancel = true;
        reset = false;
    }
}

void RootFrame_Navigated(object sender, NavigationEventArgs e)
{
    reset = e.NavigationMode == NavigationMode.Reset;
}

 

Final words

The implementation is quick and makes the app much more user friendly. Now the app will resume where we left it when we click on the app tile as you can see in the video below.