问题
I've got an intermediate "Loading" page for my game: I send them there and it has "Loading..." text that displays while the rather hefty game page loads up:
private void OnLoaded(object sender, RoutedEventArgs e)
{
Dispatcher.BeginInvoke(() =>
{
try
{
NavigationService.Navigate(new Uri("/GamePage.xaml", UriKind.Relative));
NavigationService.RemoveBackEntry();
}
catch (InvalidOperationException)
{
}
});
}
Then when you hit the back button you go to the main page rather than back to the loading screen. There's no other logic on the page.
However I just got a store submission declined: apparently on the Samsung Focus and Odyssey the navigation entry for the loading page didn't get removed, and the user is sent back to the loading page when they hit the back button, rather than back to the main menu. I'm guessing RemoveBackEntry failed.
This looks like it should work, I can't reproduce the error and I don't have a Focus or Odyssey to work with. Does anybody know what might be going wrong?
回答1:
I think you should replace:
NavigationService.RemoveBackEntry();
with:
while (NavigationService.CanGoBack)
{
NavigationService.RemoveBackEntry();
}
回答2:
You have to remember that NavigationService.Navigate
will perform the navigation asynchronously. So when you call NavigationService.RemoveBackEntry()
, the current page might not yet be on the BackStack.
To fix that, call RemoveBackEntry
in OnNavigatedTo
of GamePage.
来源:https://stackoverflow.com/questions/21845184/windows-phone-removebackentry-after-navigate-failing