There are 7 methods involves in activity life cycle in android, they are as shown in the following figure
step 1: create new project
step 2: add the following code in Main Activity
MainActivity.java
step 1: create new project
step 2: add the following code in Main Activity
MainActivity.java
import
android.app.Activity;
import android.os.Bundle;
import android.util.Log;
public class MainActivity extends Activity {
String
TAG = "Main
Activity";
@Override
protected void onCreate(Bundle
savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.d(TAG, "onCreate()");
}
@Override
protected void onStart() {
super.onStart();
Log.d(TAG, "onStart()");
}
@Override
protected void onResume() {
super.onResume();
Log.d(TAG, "onResume()");
}
@Override
protected void onRestart() {
super.onRestart();
Log.d(TAG, "onRestart()");
}
@Override
protected void onStop() {
super.onStop();
Log.d(TAG, "onStop()");
}
@Override
protected void onPause() {
super.onPause();
Log.d(TAG, "onPause()");
}
@Override
protected void onDestroy() {
super.onDestroy();
Log.d(TAG, "onDestroy()");
}
}
step 3: run the application
Now you can see the following output in LogCat.
No comments:
Post a Comment