Quickly restore application resume on WP8.1 when not connected to debugger

I am developing a WP8.1 application using MVVM Light. Fast app resume is activated by default, which is great as I want to include it in the app.

It works as expected when the application is launched from visual studio. However, problems arise when the application is launched directly on the device. The following scripts fail:

  • launch application from device launch menu
  • exit the application (using the Windows button)
  • return to the application either through the back button or through the icon in the start menu.

In step 3, the application crashes without an error message.

ps I am testing Lumia 1520

Regards, Tom

+3


source to share


1 answer


In your App.xaml.cs add this code:

private bool reset;

private void InitializePhoneApplication()
{
    if (phoneApplicationInitialized)
     return;

    RootFrame.Navigating += RootFrame_Navigating;

    RootFrame.Navigated += RootFrame_Navigated;
} 

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

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

      



And in your WMAppManifest.xml add this code:

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

      

0


source







All Articles