A frustrating issue with Fast App Resume on Windows Phone 8

Matt Hidinger of the Windows Phone Team recently wrote an excellent blog post about implementing Fast App Resume. I typically add Fast App Resume to all of my apps, as it is a feature required by all of the DVLUP challenges, and I think this navigation pattern makes sense to most users. I ran into a problem implementing Fast App Resume on my soon to be released app Car Starter though, and I wanted to share the frustrating tale that wound up having a painfully simple solution.

So, as Matt’s blog post suggests, adding Fast App Resume is pretty easy, just look for this line in your WMAppManifest.xml file and add the ActivationPolicy=”Resume” attribute.

<Tasks> <DefaultTask Name="_default" NavigationPage="ViewsMainPage.xaml" ActivationPolicy="Resume" /> </Tasks> 1 2 3 & lt ; Tasks > & lt ; DefaultTask Name = "_default" NavigationPage = "ViewsMainPage.xaml" ActivationPolicy = "Resume" / > & lt ; / Tasks >

* Don’t copy the above xml into your WMAppManifest.xml as it has a problem that I’m going to be discussing in this post, can you guess what the issue is?

After I made this change I went to test my app’s Fast Resume functionality by opening the app, going a page or two deep, hitting the start button, then clicking on the app’s icon again to relaunch the app. The expected behavior would be that you’re brought to the same page, but that didn’t happen for me! I was brought back to the MainPage instead. I first decided to uninstall the app to start fresh, maybe the change to the WMAppManifest.xml wasn’t recognized somehow? Nope, same behavior on a fresh install.

I then started to debug. I placed breakpoints in the OnNavigatedTo and OnNavigatedFrom methods of both my MainPage.xaml and the second page where I was expecting the app to return, let’s call it SecondPage.xaml. Here’s where it started to get weird. I would hit the breakpoint in SecondPage.xaml’s OnNavigatedTo! That meant Fast App Resume was working! I continued to debug and saw that I then immediately hit the OnNavigatedFrom method of SecondPage.xaml, and then hit the MainPage.xaml’s OnNavigatedTo. So why was I going into SecondPage.xaml and then immediately leaving it to return to MainPage.xaml?

After some more debugging and yelling at my phone and Visual Studio I decided to diff the WMAppManifest.xml file against other apps that I’ve released and quickly discovered my problem. You see I typically follow MVVM patterns with my app and place all of my xaml pages in a ‘Views’ sub folder. When I moved MainPage.xaml to ViewsMainPage.xaml I knew I had to make a corresponding change in WMAppManifest.xml otherwise the app would not launch. What I did not know was that the NavigationPage attribute seems to require the use of forward slashes instead of the standard windows backslash.

<Tasks> <DefaultTask Name="_default" NavigationPage="Views/MainPage.xaml" ActivationPolicy="Resume" /> </Tasks> 1 2 3 & lt ; Tasks > & lt ; DefaultTask Name = "_default" NavigationPage = "Views/MainPage.xaml" ActivationPolicy = "Resume" / > & lt ; / Tasks >

* Here’s the correct xml.

Indeed once I changed that backslash to a forward slash and relaunched my app Fast App Resume started to behave. I hope this blog post can save some other Windows Phone developers from the frustration I encountered with this issue. I also hope the Windows Phone team may take note of this issue, perhaps Visual Studio should show a warning or error when you use a backslash in this attribute.