Monday 25 July 2016

Activity Life Cycle In Xamarin Forms

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 method i.e., 

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


OnStart is called when 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 OnResume method will be called 

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



I've simply put three different break point on these three LifeCycle methods .
You can also adopt this approach now run your application when your app launches 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
It's all for App Life Cycle of Xamarin Forms
Hope it'll help ...

No comments:

Post a Comment