Forum Xamarin.Forms

how Shell.Current.GoToAsync back twice?

lescperlescper Member ✭✭✭✭✭

I opened page-1 then open page-2 then open page-3 then how to back to page-1 from page-3?

Tagged:

Best Answer

Answers

  • LeonLuLeonLu Member, Xamarin Team Xamurai

    If the page1 is root page, When you execute the navigate in Page3, you can execute Navigation.PopToRootAsync(); directly.

  • lescperlescper Member ✭✭✭✭✭

    @LeonLu if page1 is not the root page then what to do?

  • LeonLuLeonLu Member, Xamarin Team Xamurai
    edited November 2020

    @lescper First of all, You navigate step from Aboutpage=>Page1=>Page2=>Page3

    If page1 is not the root page, we can add Navigation.RemovePage(this); in Page2's OnDisappearing() method.

     public partial class Page2 : ContentPage
        {
            public Page2()
            {
                InitializeComponent();
            }
    
            private async void Button_Clicked(object sender, EventArgs e)
            {
                await Shell.Current.GoToAsync("Page3");
            }
            protected override void OnDisappearing()
            {
                base.OnDisappearing();
                Navigation.RemovePage(this);
            }
    
        }
    

    Here is running GIF.

    If you want to achieve the SingleTask in the android, it cannot be achieved. Because xamarin.forms have only one Activity when you diplay the Page.


    Xamarin forums are migrating to a new home on Microsoft Q&A!
    We invite you to post new questions in the Xamarin forums’ new home on Microsoft Q&A!
    For more information, please refer to this sticky post.

  • lescperlescper Member ✭✭✭✭✭

    @LeonLu thankyou. can I use Shell.Current.GoToAsync("../../");?

  • lescperlescper Member ✭✭✭✭✭

    there is an OnAppearing in page1 and if you remove page2 then the function will be run.

    and on this function it will open another page2.

    can you remove the page2 but do not trigger OnAppearing in page1?

  • LeonLuLeonLu Member, Xamarin Team Xamurai
    edited November 2020

    When you click an button navigate the page3, you can remove the Navigation.RemovePage(this); from OnDisappearing method to the Button_Clicked method(blew the Shell.Current.GoToAsync("Page3");), it will not execute the OnAppearing in page1.

      private async void Button_Clicked(object sender, EventArgs e)
            {
                await Shell.Current.GoToAsync("Page3");
    
                    Navigation.RemovePage(this);
    
            }
    

    Xamarin forums are migrating to a new home on Microsoft Q&A!
    We invite you to post new questions in the Xamarin forums’ new home on Microsoft Q&A!
    For more information, please refer to this sticky post.

  • lescperlescper Member ✭✭✭✭✭

    please try .it will execute the OnAppearing.

Sign In or Register to comment.