简体   繁体   中英

How to debug when the app is terminated and then launched in xamarin forms using Visual Studio

I am developing a Xamarin Forms app using Visual studio.

I want to test this scenario:

  1. I open an app
  2. Do some operations
  3. Terminate the app and launch the application
  4. Now I want to hit a break point in Visual Studio

How to achieve this? Mainly I would like to test these events - Suspended, Shutdown and Resume.

Can someone please help me out?

It has to do with Xamarin. Forms Lifecycle Methods : Put your breakpoints in following methods inside the App.xaml.cs class:

OnStart - Called when the application starts.

OnSleep - Called each time the application goes to the background.

OnResume - Called when the application is resumed, after being sent to the background.

Note that there is no method for application termination. Under normal circumstances (ie. not a crash) application termination will happen from the OnSleep state, without any additional notifications to your code.

To observe when these methods are called, implement a WriteLine call in each (as shown below) and test on each platform.

protected override void OnStart()
{
    Debug.WriteLine ("OnStart");
}
protected override void OnSleep()
{
    Debug.WriteLine ("OnSleep");
}
protected override void OnResume()
{
    Debug.WriteLine ("OnResume");
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM