OnNavigated From Window Phone 8.1

I am migrating from Windows Phone 8 to Windows Phone 8.1.

I created a Windows Phone 8.1 Store app, a hub app.

The app has created the OnNavigatedTo and OnNavigatedFrom methods

protected override void OnNavigatedTo( NavigationEventArgs e )
    {
    this.navigationHelper.OnNavigatedTo( e );
    }

protected override void OnNavigatedFrom( NavigationEventArgs e )
    {
    this.navigationHelper.OnNavigatedFrom( e );
    }

      

I put a breakpoint on OnNavigatedFrom and tried to either close the app or leave the app and the breakpoint didn't hit, meaning the app didn't reach OnNavigatedFrom.

Windows Phone 8 app breaks down into OnNavigatedFrom. Is this mechanism different with WP 8.1? if so, how?

Thank.

+3


source to share


1 answer


The problem occurs because you are running in debug mode (VS is attached). In this situation, your program behaves slightly differently in the case of navigation / suspend events, in order to test it correctly, you will have to manually raise the Suspending event ( Lifecyce events dropdown ). Normally, both events (OnNavigatedFrom and Suspending) will be triggered immediately after you leave the application.

To test it, let's put something in OnNavigatedFrom (based on a hub app from Windows Store Templates):

protected async override void OnNavigatedFrom(NavigationEventArgs e)
{
    Debug.WriteLine("OnNavigatedFrom");
    Hub.Background = new SolidColorBrush(Colors.Red);
    this.navigationHelper.OnNavigatedFrom(e);
}

      

in this case, when starting the application without a Visual Studio application, when returning to the application, the background should be red, which means that the event was fired.



There is, in fact, another huge (IMO) difference when migrating to WP8.1. WinRT - OnNavigatedTo will not be triggered when you return from suspend :

Note. On Windows Phone, OnNavigatedFrom () is called when the app is suspended. OnNavigatedTo () is not called when the app resumes.

it is only called when navigating.

A few more links: Navigation between pages , Lifecycle , Launch, resume and multitasking, and Tips for pausing an app and resuming .

+3


source







All Articles