In Mobile App Development

Whenever you undertake the process of developing Android Applications, the activity lifecycle definitely serves as the fundamental foundation stone for moving ahead towards this approach. The well-known lifecycle of an Android activity covers many stages in between its starting and finishing line, which further needs to be explained in an explanatory manner.

Does it sounds somewhat confusing? Well, worry not! Let me explain it in simple terms…

What Is Activity Lifecycle & How Does It Work?

An activity in Android is an important part of an application’s overall lifecycle, and the way the activities are launched and put together is a fundamental aspect of the Android application model. Every single activity is implemented as a subclass of the Activity base class.

Every Android Application runs on its own processes. Processes are started and stopped to run an application and also can be killed to conserve memory and resources. Activities, in turn, are run inside the main UI thread of the application’s process.

Given a chance to take an illustration, while playing games or watching videos in mobile if we get a call or message then have you ever noticed what will happen to the playing video once you complete your call. Yes, you will see that your video is stopped and again it starts from where you are playing.

It means an activity is started (playing a video) and once your process is stopped or interrupted by anything then the activity will automatically stop. In simple words, activity is a screen that user interacts with and every activity in android has lifecycle like created, started, resumed, paused, stopped or destroyed. These distinctive states are known as Activity Lifecycle.

The Activity class provides a number of callbacks that allow the activity to know that a state has changed; that the system is creating, stopping or resuming an activity, or destroying the process.

More About Activity States…

During its lifetime, an Android activity will be in one of the following states:




Activity is visible and user interacts with it


If the activity loses focus but remains visible to the user (because a smaller activity appears on top), the activity is paused


In case the activity is fully covered by another running activity, the original activity gets stopped. When an activity stops, you will lose any state and will need to re-create the current state of the user interface when an activity is restarted


Activity has been terminated by the system by calling to its finish() method.

Lifecycle Flow

The above picture shows the complete flow of Activity lifecycle.

Activity class provides set of six callbacks to navigate transitions between stages of the activity lifecycle. Better implementation of the lifecycle callbacks can help to avoid crashing, Losing the user progress and screen orientation problems.

Activity launched:

When the user stars or runs the Application on his mobile.

LifeCycle Callbacks:

This section provides conceptual and implementation information about the callback methods used during the activity lifecycle:

  • onCreate(): One must implement this callback. It is nothing but the basic activity creation startup stage when the application starts you will find a splash screen until the first main activity screen appears. You must implement this callback, to perform basic application startup logic that will happen only once in the whole lifecycle of the activity (Ex. User Application is opening).
  • onStart(): The system invokes this callback when the activity enters the started state. Once an activity comes to start method we will see the main screen of the application (Ex. Application opened and user able to see the home screen of the application).

  • onResume(): When the activity enters into this state the activity stays until the user interacts with any activity such as selecting, clicking on any options for another activity. When an interruptive event occurs the activity enters the paused state, and the system invokes the onPause() callback (Ex. User Stops an interaction with the app for a while after opening).

  • onPause(): When the user is moving from one activity to another activity the current activity gets paused and either entire process of the activity kills or it goes to Resume stage. In most cases, on pause() method called by the system when user press Home button (center button on the device). One can use the onPause() method to release the system resources, such as broadcast receivers, or any resource that affect the battery life while your activity is paused (Ex. User gets a call or message so automatically the video stops and it will starts when we click).


  • onStop(): This call back is called when the activity is no longer visible to the user, it has entered the stopped state.The system may also call onStop() method when the activity has finished running and is about to be terminated.     

  • onDestroy(): It is called before the activity is destroyed. This is the final call that the activity receives. It may also call when a screen orientation change occurs, and then immediately call onCreate() to recreate the activity. The onDestroy() callback releases all resources that have not yet been released by earlier callbacks.

  • onRestart(): It is called when the activity is being restarted, as when the activity is returning to the foreground. It is always followed by onStart() method.

    Example Code:

    Here the MainActivity class extends from Activity base class

    package com.loginworks.example;
    import android.os.Bundle;
    import android.util.Log;
    public class MainActivity extends Activity {
        public Main() {
        protected void onCreate( Bundle savedInstanceState) {
            Log.d("Life cycle","onCreate");
        protected void onStart() {
            Log.d("Life cycle","onStart");
        protected void onRestart() {
            Log.d("Life cycle","onRestart");
        protected void onResume() {
            Log.d("Life cycle","onResume");
        protected void onPause() {
            Log.d("Life cycle","onPause");
        protected void onStop() {
            Log.d("Life cycle","onStop");
        protected void onDestroy() {

    Below I have summarized that what methods are called at what time:

    1. When you start the application these methods are called by the system automatically




    2. At the point when some other application is called, while your application was running



    3. When you backpedal to your application, which was running beforehand




    4. At the point when the user presses back button to leave the application or there is no memory for the application




    The onCreate() and onDestroy() methods are called only once throughout the activity lifecycle.

I hope this blog post quenches your thirst about the knowledge for Android Activity Lifecycle in a satisfactory manner. Keep reading for more such updates…

We Are Here to Help!

Start typing and press Enter to search