Search code examples
androidwindows-phone-7lifecycle

Is there a Windows Phone 7 equivalent to Android noHistory activity attribute?


NOTICE: There has been some confusion, so let me clarify that I'm asking how to achieve something in Windows Phone 7, by comparing it to similar functionality in Android.

Question:

Learning about navigation between pages in Windows Phone 7, I implemented two-way navigation between two pages, A and B, so you can navigate from page A to B and B to A.

For illustrative purposes, let's say I navigate like this: A->B->A->B

When backing out of the application I'll be forced through each of the pages again, where ideally I only want to go through A once, and/or B once and then exit the application.

In Android you can achieve that by setting the noHistory attribute to "true" on the activity, but what about WP7?

UPDATE: Using RemoveBackEntry as suggested by keyboardP I achieved what I was looking for. For anyone else interested, this is the code I used:

private void button1_Click(object sender, RoutedEventArgs e)
        {
            NavigationService.Navigate(new Uri("/FirstPage.xaml", UriKind.Relative));
            NavigationService.RemoveBackEntry();
        }

Solution

  • In 7.0, there's no method that removes any pages from the navigation stack. However, there's a recipe you can download that will help deal with circular navigation. You can download it the Non-Linear Navigation Service from here and it's based on this article.

    I don't know if that recipe is compatible with 7.1 (Mango), but there is a new method introduced in Mango within the NavigationService called RemoveBackEntry. You could perform some calculations to figure out how many times to remove the last entry so that the user ends up on the first page when they click the back button.