views:

86

answers:

3

Hi there,

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.

+4  A: 

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.

Matt Lacey
+1  A: 

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 :)

Jobi Joy
A: 

As @Matt Lacey has said, this is almost definitely something you shouldn't do: and you will probably fall foul of the marketplace certification guidelines also:

5.2.3 Application Responsiveness After Being Deactivated

A Windows Phone application is deactivated when the user presses the Start button or if the device timeout causes the lock screen to engage. A Windows Phone application is also deactivated when it invokes a Launcher or a Chooser API. When activated, the application launch time must meet the requirements in Section 5.2.1.

Microsoft recommends that the application reestablishes the state of the application that the user experienced before the application was deactivated. For more information, see the Execution Model Overview for Windows Phone topic.

What sort of application are you making? It's hard to make a call on whether returning to the start screen is appropriate without knowing a bit more about it, or the context of the program.

Blakomen