Forum Xamarin.Android
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

Navigation stack breaks after OnResume()

RocktheFoxRoyRocktheFoxRoy Member ✭✭
edited January 28 in Xamarin.Android

I'm having a odd experience with the onResume() in my app

Here's a small Screen recording

I get breakpoints to stop and I get the Method to run but for some reason, It doesn't actually pop to the root,

And if I do get the navigation to actually work it just navigates to a dead page and the app just freezes up. I'm not actually sure how to handle the onResume() atm, The only things I need to happen is that it needs to check if theres a connection and if there is that it should just go to the home page, I'd prefer if it just continued where it left off but not to sure how that works.

  protected override void OnResume()
        {
            try
            {
                MakeWebRequest();
                if (IsConnected != true)
                {
                     MainPage = new NoInternet();
                }
                else
                {
                       //base.OnResume();
                    var nav = MainPage.Navigation;

                    nav.PopToRootAsync(true);

                    nav.PushAsync(new Home("XXXX"));
                }

            }
            catch (IOException ex)
            {

                Crashes.TrackError(ex);
            }

        }
public partial class Home : MasterDetailPage, INotifyPropertyChanged
        public App()
        {
            InitializeComponent();
            MakeWebRequest();

            try
            {

                MainPage = new NavigationPage(new Home("XXXX"));
            }
         }

Also I do not have the setting on my Phone to Destroy Activities Enabled

Answers

  • LeoZhuLeoZhu Member ✭✭✭

    Try to reset the MainPage in the OnResume method .

    protected override void OnResume()
        {
           try
            {
                MakeWebRequest();
                if (IsConnected != true)
                {
                     MainPage = new NoInternet();
                }
                else
                {
                      MainPage = new NavigationPage(new MainPage());
                }
    
            }
            catch (IOException ex)
            {
    
                Crashes.TrackError(ex);
            }
    
        }
    
  • RocktheFoxRoyRocktheFoxRoy Member ✭✭

    Doesn't work Sadly exact same result Heres a sample app https://github.com/Lirian21/SampleApp if that helps got the same issue

  • LeoZhuLeoZhu Member ✭✭✭

    @RocktheFoxRoy Maybe you could try to set the HomePage as singleton

Sign In or Register to comment.