Android Activity Lifecycle

Android Activity Lifecycle Description 

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

An action is the single screen in android. It is similar to window or edge of Java.

By the assistance of action, you can put all your UI segments or gadgets in a solitary screen.

The 7 lifecycle strategy for Activity depicts how movement will act at distinctive states.

Android Activity Lifecycle methods

We should see the 7 lifecycle strategies for android movement.

MethodDescription
onCreatecalled when activity is first created.
onStartcalled when activity is becoming visible to the user.
onResumecalled when activity will start interacting with the user.
onPausecalled when activity is not visible to the user.
onStopcalled when activity is no longer visible to the user.
onRestartcalled after your activity is stopped, prior to start.
onDestroycalled before the activity is destroyed.



Android Activity Lifecycle Example

It gives the insights about the conjuring of life cycle techniques for action. In this case, we are showing the substance on the logcat.

File: MainActivity.java
package com.example.activitylifecycle;  
import android.os.Bundle;  
import android.app.Activity;  
import android.util.Log;  
import android.view.Menu;  
public class MainActivity extends Activity {  
    @Override  
    protected void onCreate(Bundle savedInstanceState) {  
        super.onCreate(savedInstanceState);  
        setContentView(R.layout.activity_main);  
        Log.d("lifecycle","onCreate invoked");  
    }  
    @Override  
    protected void onStart() {  
        super.onStart();  
         Log.d("lifecycle","onStart invoked");  
    }  
    @Override  
    protected void onResume() {  
        super.onResume();  
         Log.d("lifecycle","onResume invoked");  
    }  
    @Override  
    protected void onPause() {  
        super.onPause();  
         Log.d("lifecycle","onPause invoked");  
    }  
    @Override  
    protected void onStop() {  
        super.onStop();  
         Log.d("lifecycle","onStop invoked");  
    }  
       @Override  
    protected void onRestart() {  
        super.onRestart();  
         Log.d("lifecycle","onRestart invoked");  
    }     
    @Override  
    protected void onDestroy() {  
        super.onDestroy();  
         Log.d("lifecycle","onDestroy invoked");  
    }  
}  


Output:





0 comments:

Post a Comment

My Instagram