Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Navigation in Application Activated Windows Phone 7 (Tombstoning)

Whenever my program is closed via tombstoning, when it is reactivated I would like the application to Navigate back to the start screen.

I would like to do something like this

private void Application_Activated(object sender, ActivatedEventArgs e) { NavigationService.Navigate(new Uri("/Start.xaml", UriKind.Relative));
}

but it doesn't work. Thanks, Shureman.

like image 229
shureman Avatar asked Oct 12 '10 01:10

shureman


3 Answers

That's not the generally accepted behaviour around tombstoning. The expectation is that the app should return exactly as it was when the user left. Remember that tombstoning may be a result of something other than a user initiated action within the app. For instance, as a user, I wouldn't want an app to forget all the information I've entered and return to a previous screen just because I answered a phone call.

If you really wanted to do this, how it could be done would depend on the structure of your application and the navigation hierarchy.

Your best bet would probably be to build your own navigation system.
If you wanted to use the built in back stack. Your Application_Activated event could set a global flag that all pages will pick up in their OnNavigatedTo event and then respond to by navigating backwards. This backwards navigation would likely be visible (if only briefly) to the user and create a less than desirable experience.

Update
It's now possible to do something like this using the Non-Linear Navigation Service.

like image 117
Matt Lacey Avatar answered Sep 27 '22 02:09

Matt Lacey


I second Matt, that is not a recommended behavior by the MSFT guidelines. WP7 user will expect the app to be tomb stoned properly.

And if you are still stringent on doing this here is the way: Use NavigationService.GoBack() as many times as you navigated. Technically WP7 keeps all the page transition you already did in the system and you can program to go back to the home page. You might need to wait for the NavigationCompleted event then call the next GoBack() and call it untill NavigationService.CanGoBack is false , which will be your home page :)

like image 37
Jobi Joy Avatar answered Sep 23 '22 02:09

Jobi Joy


Dont listen to all these do gooders who quote guidlines yawn

try this

private void Application_Activated(object sender, ActivatedEventArgs e)
{
    RootFrame.Navigated += RootFrame_Navigated;
}

void RootFrame_Navigated(object sender, NavigationEventArgs e)
{
    RootFrame.Navigated -= RootFrame_Navigated;
    RootFrame.Navigate(new Uri("/TestPage.xaml", UriKind.Relative));
}
like image 27
Clinton Ward Avatar answered Sep 24 '22 02:09

Clinton Ward