0

I am using the APP to connect to a device in Xamarin debug mode.

When the system is trying to connect to the device(like the screenshot shows "Connecting to device..."), if I press the back button to home(desktop) and back to APP, I find that the code will run App.xaml.cs again, so I will see the screen will show Example_A_Page again and then show Example_B_Page afterward.

Then I tried again without the debug mode this time. When I press the back button to home(desktop) and then back to APP, APP is still running Example_B_Page.

Does anybody know why this situation happened?

Here is the pseudo code

public partial class App : Application
{
    public App()
    {
        InitializeComponent();
        MainPage = new NavigationPage(new Example_A_Page());
    }
}

public partial class Example_A_Page : ContentPage
{
    public Example_A_Page()
    {
        InitializeComponent();
    }

    protected async override void OnAppearing()
    {
        await Navigation.PushPopupAsync(new Example_B_Page());
    }
}

public partial class Example_B_Page : ContentPage
{
    public Example_B_Page()
    {
        InitializeComponent();
    }

    private async void Button_Clicked(object sender, EventArgs e)
    {
        //Do the connection behavior...
        //Connected to the device...
    }
}

enter image description here enter image description here

Hannah.C
  • 21
  • 5
  • `OnAppearing()` is executed everytime the page becomes visible. This is the case when it first gets created but also when the page gets hidden and then becomes visible again. That's also what the name implies. You should move the code that opens the popup page somewhere else. E.g. into an event handler. – Julian Dec 26 '22 at 15:36
  • Did that mean the App restarted when press to Home? You could add some debug info to track the Application states in this process. That might be helpful. – Liqun Shen-MSFT Dec 27 '22 at 06:08

0 Answers0