Xamarin Forms Activity Lifecycle

Before starting with Xamarin Forms it's important that we should have a strong knowledge of Xamarin Forms Activity Life Cycle.

So without wasting any time let's dive into it.

Let's create a Xamarin Forms Project in Visual Studio 2015 or Xamarin Studio.

Once you've successfully created a Xamarin Forms Project then you'll see App.cs Page. Open it up and in this App.cs you'll see three different activity methods;  i.e.,

  1. OnStart()
  2. OnSleep()
  3. OnResume()

OnStart is called the first time you launch an application.

OnSleep
is called when your activity goes into the background state.

OnResume is called when your activity again comes on the front screen or simply says when your application comes from the OnSleep state, then the OnResume method will be called.

Enough for this for now --  it's time to put in some break point and try to implement this life cycle in your Xamarin Forms Application.

Forms

I've simply put three different break points on these three Lifecycle methods .

You can also adopt this approach to run your application. When your app launches for the  first time then you will notice that OnStart method will be called by using breakpoint. Similarly, when you press the back button of your device your application will now go to the sleep state and when you again want to resume your application then OnResume will be fired.

That's all for App Life Cycle of Xamarin Forms.