Reputation: 1123
I am moving from Windows Phone 8 to Windows Phone 8.1.
I Created a Windows Phone 8.1 Store Application, Hub App.
The application 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 in the OnNavigatedFrom and tried to either close the application, or to leave the application and the breakpoint is not hit, i.e. the application doesn't reach the OnNavigatedFrom.
A Windows Phone 8 application is breaking on the OnNavigatedFrom. Is the mechanism is different with WP 8.1? if so how?
Thanks.
Upvotes: 3
Views: 3341
Reputation: 29792
The problem seems to occur, because you are running in Debug mode (VS attached). In this situation your program behaves little different in case Navigation/Suspend events, to test it properly you will have to invoke the Suspending event manually (Lifecyce events dropdown). In normal situation both events (OnNavigatedFrom and Suspending) will be called just after you leave the app.
To test it let's put something in OnNavigatedFrom (basing on 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 you run the app without Visual Studio attached, when you return to the app the background should be red - which means that the event has been fired.
There is, in fact, one more huge (IMO) difference when moving to WP8.1 WinRT - OnNavigatedTo won't be fired when you come back from suspension:
Note On Windows Phone, OnNavigatedFrom() is called when the app is suspended. OnNavigatedTo() is not called when the app is resumed.
it's called only when you navigate.
Some more references: Navigating between pages, Lifecycle, Launching, resuming, and multitasking and Guidelines for app suspend and resume.
Upvotes: 3