0
votes

I am developing a Windows Phone 8.1 app. In that I need to to navigate from

Page1 --> Page2--> Page3

But I don't want Page1 to apper again when I keep on pressing back button.

Page3-->Page2-->Exit the app

I was able to achieve this using Frame.BackStack.Clear() in the OnNavigatedFrom() of Page1. But the problem is when I click the app icon again its only launching from Page2 not from Page1.

So I want to understand, why the back stack is not  cleared when we press 
back button and exit the app. And how to achieve the behavior I require
2

2 Answers

1
votes

Windows Phone 8.1 Store apps do not close when you are navigating back from the first page. Instead they only get suspended. So once you start open it again, you end up on the last running instance of the app again, this includes backstack, page state, etc.

In the app.xaml.Cs's OnLaunched handler, you can intercept this behavior: You can check the e.PreviousExecutionState where you can check, if you want to handle it as a real restart.

In that case you just dump the current Frame and replace it with a new one, or clear the backstack and start with a new navigation.

Also: The Backstack is a list. You can remove single entries any time and not only completely clear it with the RemoveAt method.

0
votes

Your methods sounds okay to me. It is that the app runs behind the scene. Unless you write a code like this it will keep running in the last position you kept.

Application.Current.Exit();