What is an Activity?

In Android an activity represents a single screen or window with a user interface. It is like window or frame of Java.The android Activity is the subclass of ContextThemeWrapper class. By the help of activity, you can place all your UI components or widgets in a single screen. Android activity is the subclass of ContextThemeWrapper class. Activity User Interface defines in XML file and the background programming of that UI construct in Activity Class (Java File).

Android Activity Lifecycle

Before Launching, an Activity go through some events and each event has corresponding methods which are called at that event. Android Activity Life Cycle is controlled by 7 methods of Android App Activity class.As the user navigate within apps or leave/re-enter to your app activity call a sequence of callback methods to maintain the state of activity. Here we describe 7 lifecycle events and callbacks of Activity that how they behave at different states.



You must implement this callback, which fires when the system first creates the activity. On activity creation, the activity enters the Created state. In the onCreate() method, you perform basic application start-up logic that should happen only once for the entire life of the activity. For example, your implementation of onCreate() might bind data to lists, initialize background threads, and instantiate some class-scope variables.

onCreate(Bundle) is where you initialize your activity. Most importantly, here you will usually call setContentView(int) with a layout resource defining your UI, and using findViewById(int) to retrieve the widgets in that UI that you need to interact with programmatically.

This method receives the parameter savedInstanceState, which is a Bundle object containing the activity's previously saved state. If the activity has never existed before, the value of the Bundle object is null.


When the activity enters the Started state, android calls the onStart() method which makes the activity visible to the user and prepares the activity to enter the foreground and become interactive.


When the activity enters the Resumed state, it comes to the foreground, and then the system invokes the onResume() callback. This is the state in which the app interacts with the user.

The app stays in this state until user take focus away from the app. For Ex. user navigating to another activity, or the device screen's turning off.

As user left the screen the activity enters in the Paused() state, and the system invokes the onPause() callback.


The system calls this method as the first indication that the user is leaving your activity.

You can use this method to release some system resources, such as broadcast receivers, handles to sensors (like GPS), or any resources that may affect battery life while your activity is paused and the user does not need them.


When your activity is no longer visible to the user, it has entered the Stopped state.


When you comes back to your activity then it first call the onRestart callback and then onStart()again().


Called before the activity is destroyed due to calling finish() method or application termination.


Graphical Flow Layout of Activity Life Cycle

below image show how an activity switches between multiple states.

Let's create a simple example to catch the Activity Events.

Lets view a example which demonstrate the multiple events before resuming the activity on screen.

Your xml Layout should look like this..

	<RelativeLayout xmlns:android="https://schemas.android.com/apk/res/android"
    tools:context="dzone.jaipur.myapp1.MainActivity" >

        android:text="Hello World" />

Write this code in your java File (Android Activity).

public class MainActivity extends AppCompatActivity {

    protected void onCreate(Bundle savedInstanceState) {

		 Log.d("lifecycle","onCreate invoked");  

    protected void onStart() {  
         Log.d("lifecycle","onStart invoked");  

    protected void onResume() {  
         Log.d("lifecycle","onResume invoked");  

    protected void onPause() {  
         Log.d("lifecycle","onPause invoked");  

    protected void onStop() {  
         Log.d("lifecycle","onStop invoked");  

    protected void onRestart() {  
         Log.d("lifecycle","onRestart invoked");  

    protected void onDestroy() {  
         Log.d("lifecycle","onDestroy invoked");



Now Run the Application and get the desired output in Log File.

Why Us?


  • 257,katewa nagar,gujjar ki thadi,new sanganer road, Jaipur, Jaipur
  • Phone:+919829708506
  • Email:[email protected]

Follow Us