11 June 2014

The Life cycle of Android .....

Here I will discuss the life cycle of an Android Application...
The Life cycle of an Android Application has 4 states and 7 methods.
Lets name them :

The four states :
  1. Activity Launched
  2. Activity Running
  3. App process killed
  4. Activity shutdown
The  seven methods :
  1. onCreate()
  2. onStart()
  3. onRestart()
  4. onResume()
  5. onPause()
  6. onStop()
  7. onDestroy()
The lifecycle diagram is shown below :
android lifecycle diagran
Life cycle of Android Activity


Are you able to see all the 4 methods and the 7 methods .
In the previous post we discussed about Activity class . It lets you connect to the UI (XML) .

The 7 methods are declared in class Activity .
  •  When the Activity is launched  (i.e. you clicked the icon to start the App) the onCreate() method start to execute onCreate() corresponds to main method in Core Java .
  • The onCreate() method is followed by onStart() and onResume() . When in onResume() state your first page is displayed on the screen .
NOTE : You do not have to mention the methods explicitly in your code unlike MIDlet programming, where you have to mention all the methods even if you do not write anything under them .
  • onPause() method is used when you pause an application (when your application runs in background).
These screenshot shows 4 apps in background (in onPause() is being executed for the Activity class of these apps)
in pause

  •  onStop() method is called the you are removing an application from memory (Pressing End for any app in the above screenshot) .
  • onDestroy() method is called as soon as onStop() method is called .
  • The onDestroy() method removes the application from memory and free the resources of the device  .
Stay Tuned with Made In Android

Previous Page Next Page Home

No comments:

Post a Comment

Top