Articles → ANDROID → Activity life cycle in android

Activity life cycle in android






Events




Picture showing the flow chart of activity life cycle in android

Click to Enlarge












































Example




package com.example.demo_activity;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Log.v("METHOD", "onCreate method called");
    }

    @Override
    protected void onStart() {
        super.onStart();
        Log.v("METHOD", "onStart method called");
    }

    @Override
    protected void onResume() {
        super.onResume();
        Log.v("METHOD", "onResume method called");
    }

    @Override
    protected void onPause() {
        super.onPause();
        Log.v("METHOD", "onPause method called");
    }

    @Override
    protected void onStop() {
        super.onStop();
        Log.v("METHOD", "onStop method called");
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        Log.v("METHOD", "onDestroy method called");
    }

    @Override
    protected void onRestart() {
        super.onRestart();
        Log.v("METHOD", "onRestart method called");
    }
}



Output


-- ON LOAD OF ACTIVITY FOR THE FIRST TIME
2019-08-27 15:42:40.878 10837-10837/com.example.demo_activity V/METHOD: onCreate method called
2019-08-27 15:42:40.893 10837-10837/com.example.demo_activity V/METHOD: onStart method called
2019-08-27 15:42:40.896 10837-10837/com.example.demo_activity V/METHOD: onResume method called

-- ON MINIMIZING THE ACTIVITY
2019-08-27 15:42:50.025 10837-10837/com.example.demo_activity V/METHOD: onPause method called
2019-08-27 15:42:50.064 10837-10837/com.example.demo_activity V/METHOD: onStop method called

-- ON RESTARTING THE ACTIVITY AFTER MINIMIZING
2019-08-27 15:42:52.878 10837-10837/com.example.demo_activity V/METHOD: onRestart method called
2019-08-27 15:42:52.882 10837-10837/com.example.demo_activity V/METHOD: onStart method called
2019-08-27 15:42:52.884 10837-10837/com.example.demo_activity V/METHOD: onResume method called

-- ON CLOSING THE APPLICATION
2019-08-27 15:44:32.599 10837-10837/com.example.demo_activity V/METHOD: onDestroy method called



Posted By  -  Karan Gupta
 
Posted On  -  Friday, September 20, 2019
 
Updated On  -  Friday, April 03, 2020

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250