What is Activity?

Activity is an individual User interface screen where visual elements are called views or widgets.

Two different ways to create widgets are

1.Java Code,
2.XML Code

Application can have more than one activity

Each Should be defined in manifest.xml

Each Activity in android is a subclass of Activity class in Android SDK.

Four States of Activity?

1.Active or running


Activity Life Cycle?



Callback methods : 

onCreate() : This is the first callback and It is called when the activity is first created.

onStart() : This call back is called when the activity is visible to the user.Still not active

onResume() : Activity is visible and active for user interaction.Activity will be placed on top of activity stack.

onPause() : Called when user starts another activity or navigates to some other feature of system.This callback is last guarantee call before destroying activity.

onStop(): Called when activity is no longer visible.

onDestroy(): Called before destroying activity

onRestart() : Called when the activity restarts after stopping it.

onPause State

1.User pressed HOME button
2.Another activity on top does not completely obscures the visibility.
3.The device goes to sleep
4.It gets killed by system under low memory conditions.No methods will be called before destruction of activity.Need to rerun by calling onCreate(),and restore previous configuration by using bundle object.
5.User resumes the activity by calling onResume().

Stop State

1.System kills to free the resources.It needs to restart cycle again by calling onCreate().
2.It is restarted by calling onRestart(),onStart(),onResume().In this case no need to restore

Activity Lifecycle Loops

Three Life cycle loops exists for every activity.They are

1.Entire Lifetime: Between onCreate() – onDestroy()
2.Visible Lifetime: Between onStart() – onStop(),User May or May-not be able to interact with activity.
3.Foreground Lifetime : Between onResume() – onPause(),User can interact with activity,On top of all other activity. Completely visible