Saturday, 5 March 2016


Android Activity Lifecycle

Android Activity Lifecycle is controlled by 7 methods of android.app.Activity class. The android Activity is the subclass of ContextThemeWrapper class.
An activity is the single screen in android. It is like window or frame of Java.


there are some type pf methods .

onCreate-called when activity is first created.
onStart-called when activity is becoming visible to the user.
onResume-called when activity will start interacting with the user.
onPause-called when activity is not visible to the user.
onStop-called when activity is no longer visible to the user.
onRestart-called after your activity is stopped, prior to start.
onDestroy-called before the activity is destroyed.


  1. package com.vinodsonava.activitylifecycle;  
  2. import android.os.Bundle;  
  3. import android.app.Activity;  
  4. import android.util.Log;  
  5. import android.view.Menu;  
  6. public class MainActivity extends Activity {  
  7.     @Override  
  8.     protected void onCreate(Bundle savedInstanceState) {  
  9.         super.onCreate(savedInstanceState);  
  10.         setContentView(R.layout.activity_main);  
  11.         Log.d("lifecycle","onCreate invoked");  
  12.     }  
  13.     @Override  
  14.     protected void onStart() {  
  15.         super.onStart();  
  16.          Log.d("lifecycle","onStart invoked");  
  17.     }  
  18.     @Override  
  19.     protected void onResume() {  
  20.         super.onResume();  
  21.          Log.d("lifecycle","onResume invoked");  
  22.     }  
  23.     @Override  
  24.     protected void onPause() {  
  25.         super.onPause();  
  26.          Log.d("lifecycle","onPause invoked");  
  27.     }  
  28.     @Override  
  29.     protected void onStop() {  
  30.         super.onStop();  
  31.          Log.d("lifecycle","onStop invoked");  
  32.     }  
  33.        @Override  
  34.     protected void onRestart() {  
  35.         super.onRestart();  
  36.          Log.d("lifecycle","onRestart invoked");  
  37.     }     
  38.     @Override  
  39.     protected void onDestroy() {  
  40.         super.onDestroy();  
  41.          Log.d("lifecycle","onDestroy invoked");  
  42.     }  
  43. }  

1 comment:

  1. Good for Helpful for me and good to learn for beginners
    Thanks
    Ravi kumar

    ReplyDelete