Activity Lifecycle – Learn about Activity Lifecycle in Android

activity lifecycle

In this video tutorial, you will learn about Activity Lifecycle in Android. Activity lifecycle describes the various stages through which an android activity passes while execution. In activity lifecycle, when an activity is launched, it executes onCreate() function. The code in this function will be executed right after launching android app activity. After it, the control goes to onStart() function and it loads & executes the code in this section. After it the control goes to onResume() function where it resumes if there is anything paused. At this stage, the current status of Activity will be running. If any other activity is launched, onPause() function is invoked. On ending of new activity, control goes to onResume() again where it resumes previous activity. From onPause(), the control can go to onStop(), where to start previous activity, onRestart() function will be invoked. After onStop(), in normal flow, the activity will be destroyed by invoking onDestroy() method.

An example of this can be seen below.

package com.example.imarslan;

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

public class MainActivity extends Activity {
   String msg = "Android : ";
   /** Called when the activity is first created. */
   public void onCreate(Bundle savedInstanceState) {
      Log.d(msg, "The onCreate() event");

   /** Called when the activity is about to become visible. */
   protected void onStart() {
      Log.d(msg, "The onStart() event");

   /** Called when the activity has become visible. */
   protected void onResume() {
      Log.d(msg, "The onResume() event");

   /** Called when another activity is taking focus. */
   protected void onPause() {
      Log.d(msg, "The onPause() event");

   /** Called when the activity is no longer visible. */
   protected void onStop() {
      Log.d(msg, "The onStop() event");

   /** Called just before the activity is destroyed. */
   public void onDestroy() {
      Log.d(msg, "The onDestroy() event");


Watch Next Tutorial: Create IDENTITY, a small project in Android

Author: Arslan ud Din Shafiq

Alibaba Cloud MVP, Alibaba Cloud Technical Author, Dzone MVB, Software Engineer, Software Developer, Software Designer, Web Engineer, Web Developer, Web Designer, Database Designer, Database Developer, Cloud Computing Specialist, Linux Expert, Servers, 3D Modeling, Blogger, Facebook Map Editor, Google Map Editor

2 thoughts on “Activity Lifecycle – Learn about Activity Lifecycle in Android

Leave a Reply

Your email address will not be published. Required fields are marked *