Android Tutorial – Android Activity Lifecycle

Android Tutorial
Android Tutorial

Android Activity Lifecycle is controlled by 7 techniques for class. The android Activity is the subclass of ContextThemeWrapper class.

A movement is the single screen in android. It resemble window or edge of Java. By the assistance of action, you can put all your UI parts or gadgets in a solitary screen. The 7 lifecycle technique for Activity depicts how action will act at various states.


You should always call up to your superclass when implementing these methods.

public class Activity extends ApplicationContext {
     protected void onCreate(Bundle savedInstanceState);

     protected void onStart();

     protected void onRestart();

     protected void onResume();

     protected void onPause();

     protected void onStop();

     protected void onDestroy();

 Activity Lifecycle

■ Activities in the foreground are running (onResume)
■ If something transparent obscurs the activity it is paused (onPause)
■ If you can’t see the activity it is stopped. (onStop)
■ If it is garbage collected (onDestroy)
Android Activity
Life Cycle
  •  Lifetime:
    • onCreate() to
    •  onDestroy()
  •  Visible when:
    •  onStart() to
    •  onStop()
  •  Foreground
    •  onResume to
    •  onPause()

 Android Activity Lifecycle Example

In this example, we are displaying the content on the logcat.


package com.example.activitylifecycle;  
import android.os.Bundle;  
import android.util.Log;  
import android.view.Menu;  
public class MainActivity extends Activity {  
    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");  


Partner Sites

Be the first to comment

Leave a Reply

Your email address will not be published.