button back to my app in the background and when you resume it starts again

I am developing an app in Xamarin.Forms, before I was trying to make a master detail page to become my MainPage when I logged in to my app, this I have already achieved. Now I have the problem that when I use the button behind the phone my app is miimiza and goes to the background which is the behavior I hope, but when I return to my app does not continue showing my master detail page, but returns to my LginPage.

It is as if my app was running twice or at least there were two instances of LoginPage existing at the same time, this is because in my LoginPage I trigger some DisplayAlert according to some messages that my page is listening through the MessaginCenter and they are they shoot twice.

Can someone tell me how I can return the same to my app on the master detail page and not restart in the strange way described?
Thanks.

Best Answers

  • lavilasolavilaso ✭✭
    Accepted Answer

    The first problem I have solved like this:

    Part of my App.xaml.cs:

    public App()
    {
        if (IsLoged)
        {
            MainPage = new MyMasterDetailPage();
        }
        else
        {
            MainPage = new NavigationPage(new WelcomePage());
        }
    }
    

    The second problem I have solved using Application.Current.MainPage.DisplayAlert (); instead of the MessagingCener

Answers

  • hng78hng78 IDMember ✭✭

    have you try
    OnSleep --> Clear the message
    OnResume --> Re-register your message

    assuming this the source of problem

  • ColeXColeX Member, Xamarin Team Xamurai

    Why is there existing two instances of LoginPage? Can you show the logic code ?

  • lavilasolavilaso Member ✭✭

    @ColeX said:
    Why is there existing two instances of LoginPage? Can you show the logic code ?

    I subscribed two times to the message, I have already solved it. in the next answer I show it.

  • lavilasolavilaso Member ✭✭
    Accepted Answer

    The first problem I have solved like this:

    Part of my App.xaml.cs:

    public App()
    {
        if (IsLoged)
        {
            MainPage = new MyMasterDetailPage();
        }
        else
        {
            MainPage = new NavigationPage(new WelcomePage());
        }
    }
    

    The second problem I have solved using Application.Current.MainPage.DisplayAlert (); instead of the MessagingCener

Sign In or Register to comment.