Xamarin.Forms Life Cycle
Xamarin.Form is a platform to develop the cross-platform mobile application by using the XAML for Front-End and C# for the backend of the application. In Xamarin.Form application, we can share all code. Xamarin.Forms also give the 100% API coverage of Android and iOS native APIs. So that, we can develop native Android, iOS, and Windows apps.
The life cycle of Xamarin.Forms applications:
When we create Xamarin.Forms application, we will see four projects:
We can see all four projects in this screenshot:
Xamarin.Forms application lifecycle consists of three virtual methods that are overridden to handle the lifecycle method. These methods are present in App. Xaml. Cs class in a portable project.
We find all these files here, shown in the screenshot:
The three methods are:
These three methods are called when the application is in the state of start, sleep, or resume. There is no method for the termination of the application. Application terminates from OnSleep() method without any additional notification.
We can see all these files in the App.Xaml.cs in our Xamarin.Forms (portable project).
OnStart() method calls when the application starts for the first time. When the application starts, it reads all the code written in the OnStart() method.
Syntax of OnStart() method can be written as below:
OnSleep() method calls when the application is in the sleep mode, i.e., when there is no work in the application. Sleep method calls when the user hides the application. In this form, our application is open in the background in the sleep state.
Syntax of OnSleep() method can be written as below:
OnResume() method is called when we come back to the application from sleep mode.
Syntax of OnResume() method can be written as below:
Let's put breakpoints on all these methods, and we will see all of these methods called when the application is in one of these states.