Forum Xamarin.Forms

Changing main/root page: Problems with android

Hi
I am building an application where i need to remove the initial page from the navigation stack. When started the user is presented with a login screen which I want to have removed from the stack after the user have been successfully logged in. I have tried several approaches:

  • Setting a new MainPage
  • Removing the page from the stack using navigationPage.Navigation.Removepage(page p)

Both of these work ok on ios but not on android. Whenever i rotate the phone or switches out of the app and back in again the loginpage will always be shown.

I cannot figure out if this is a bug or if I am doing something wrong here. Do any of you know an approach to working around this problem? It literally makes me crazy!

Thank you very much in advance and have a great day.

Answers

  • AdamPAdamP AUUniversity ✭✭✭✭✭

    @KennethBrodersen - rotating the page shouldn't switch the MainPage back or change your NavigationStack. Are you sure something isn't reinitializing your navigation stack when coming back into the app?

  • KennethBrodersenKennethBrodersen USMember ✭✭

    @AdamP
    In my MainActivity I initialize Forms in the onCreate method while my initialization of services (and creation of the mainpage) is performed in the OnStart method of the Application class. I believe this is the correct way to perform these tasks?
    If I change the behaviour so i just push my second page on top of the stack (instead of replacing the main page with it) the app behave correctly.

Sign In or Register to comment.