RemovePage is not supported globally on Android

JassimRahmaJassimRahma USMember ✭✭✭

Hi,

Why I am getting:

RemovePage is not supported globally on Android

when I try:

Navigation.RemovePage(this);

although I have this in my App.xaml.cs:

MainPage = new NavigationPage(new MainPage())
{
BarBackgroundColor = Color.White,
BarTextColor = Color.Black
};

Best Answer

Answers

  • yelinzhyelinzh Member, Xamarin Team Xamurai

    I've deplyed a demo.When I click the button in page1, it navigates to page2. And clicking the button in page2, it'll go back to page1.As the image shows. What's the problem you faced of using Navigation.RemovePage?
    page1.xaml.cs

    public partial class Page1 : ContentPage
    {
        public Page1()
        {
            InitializeComponent();
        }
    
        private void Button_Clicked(object sender, EventArgs e)
        {
            Navigation.PushAsync(new Page2());
        }
    }
    

    page2.xaml.cs

    public partial class Page2 : ContentPage
    {
        public Page2()
        {
            InitializeComponent();
        }
    
        private void Button_Clicked(object sender, EventArgs e)
        {
            Navigation.RemovePage(this);
        }
    }
    

  • JassimRahmaJassimRahma USMember ✭✭✭
    edited April 12

    My SIgnup page is a Modal page shown using:

    await Navigation.PushModalAsync(new Signup());

    and my activation page is also Modal page shown using:

    await Navigation.PushModalAsync(new Activate(TextBoxSignupEmailAddress.Text));
    

    So it's like this:

    1. From MainPage I am showing SIgnup page using PushModalAsync
    2. From Signup page I am Showing Activation page using PushModalAsync
    3. Upon showing Activatio, before or After, I want to remove the Signup page
  • JohnHardmanJohnHardman GBUniversity mod
    edited April 12

    @JassimRahma said:
    My SIgnup page is a Modal page shown using:

    await Navigation.PushModalAsync(new Signup());

    and my activation page is also Modal page shown using:

    await Navigation.PushModalAsync(new Activate(TextBoxSignupEmailAddress.Text));
    

    So it's like this:

    1. From MainPage I am showing SIgnup page using PushModalAsync
    2. From Signup page I am Showing Activation page using PushModalAsync
    3. Upon showing Activatio, before or After, I want to remove the Signup page

    As per the documentation at https://docs.microsoft.com/en-us/dotnet/api/xamarin.forms.inavigation.removepage?view=xamarin-forms , RemovePage "Removes the specified page from the navigation stack". That's the navigation stack, not the modal stack.

    If you continue to use modal pages, you will want to make use of PopModalAsync

  • JassimRahmaJassimRahma USMember ✭✭✭

    but the problem if I use the PopModalAsync it will not invoke the RemovePage whether I use it before or after the PopModalAsync

  • JohnHardmanJohnHardman GBUniversity mod

    @JassimRahma said:
    but the problem if I use the PopModalAsync it will not invoke the RemovePage whether I use it before or after the PopModalAsync

    @JohnHardman said:
    If you continue to use modal pages, you will want to make use of PopModalAsync

    That's PopModalAsync instead of RemovePage, not as well as RemovePage

  • JassimRahmaJassimRahma USMember ✭✭✭

    but there is a problem here..

    if I use this from the Signup page:

    await Navigation.PushModalAsync(new Activate(TextBoxSignupEmailAddress.Text));
    
    await Navigation.PopModalAsync();
    

    it will open the Activation page and close it again immediately instead of closing the Signup page

    and if I use:

    await Navigation.PopModalAsync();
    
    await Navigation.PushModalAsync(new Activate(TextBoxSignupEmailAddress.Text));
    

    it will close the Signup page without even opening the Activation page

  • JohnHardmanJohnHardman GBUniversity mod

    @JassimRahma said:
    but there is a problem here..

    Not really, you just need to sequence things correctly.

    I'm not going to write the code for you, as the best way to learn is to work through these things. So I'll point you in a direction that should work (working on the basis that you want to use modal pages, which isn't necessarily what I would do).

    If you work on the basis that you need to do the PushModalAsync from MainPage, how could your Signup page notify the MainPage that the Signup page should be popped and the ActivationPage should be pushed?

  • JassimRahmaJassimRahma USMember ✭✭✭

    I tried everything @JohnHardman

    I even tried:

    Navigation.PushModalAsync(new NavigationPage(new Signup()));

    but if I keep the:

    await Navigation.PopModalAsync();

    before the opening the page it will just close the current page and if I keep it after open the page it will close the Activate page I have just opened.

  • JohnHardmanJohnHardman GBUniversity mod

    @JassimRahma said:
    I tried everything @JohnHardman

    I even tried:

    Navigation.PushModalAsync(new NavigationPage(new Signup()));

    but if I keep the:

    await Navigation.PopModalAsync();

    before the opening the page it will just close the current page and if I keep it after open the page it will close the Activate page I have just opened.

    Did you make the pop and push calls from MainPage?

  • JassimRahmaJassimRahma USMember ✭✭✭

    How? I never tried that...

Sign In or Register to comment.