Understanding Android Activity Lifecycle (Part One)

Hello lets talk about Android Activity life cycle hmm.
We know there are three buttons in android phone at bottom Back, Home, and Multitask.

There are seven methods to control android activity life cycle

onCreate()
onRestart()
onStart()
onResume()
onPause()
onStop()
onDestroy()

An Application which have only one Activity and life is beautiful.

Action: App icon clicked

In the onCreate() method
In the onStart() method
In the onResume() method

Action: Home Button clicked

In the onPause() method
In the onStop() method

we can retrieve the activity in two way

case 1:
Action: Multitask Button clicked, we selected our app

In the onRestart() method
In the onStart() method
In the onResume() method

case 2:
Action: App icon clicked

In the onRestart() method
In the onStart() method
In the onResume() method

Action: Back button clicked

In the onPause() method
In the onStop() method
In the onDestroy() method

observations: we can clearly say that onCreate() method is called once when the activity first started and onDestroy() is also called once when the activity is killed (android removes the activity from the memory). But when we pressed the home button or multitask button android sends the activity in the background (the activity still there in the memory). After that we can bring the activity in the foreground by clicking the app icon or from multitask button. well its not as easy as it seems. Later i will discuss more about multiple activity.

activity_lifecycle

Source: http://developer.android.com/reference/android/app/Activity.html

Download Source Code

Enjoy !

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s