In this diagram shows the important state paths of an Activity. The square rectangles represent callback methods you can implement to perform operations when the Activity moves between states. The colored ovals are major states the Activity can be in.kChdb

 

package com.androidsubway.activitylifecycle;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

Log.d("Activity Life Cycle", "onCreate()");
}

@Override
protected void onStart() {
super.onStart();

Log.d("Activity Life Cycle", "onStart()");
}

@Override
protected void onResume() {
super.onResume();

Log.d("Activity Life Cycle", "onResume()");
}

@Override
protected void onPause() {
super.onPause();

Log.d("Activity Life Cycle", "onPause()");
}

@Override
protected void onRestart() {
super.onRestart();

Log.d("Activity Life Cycle", "onRestart()");
}

@Override
protected void onStop() {
super.onStop();

Log.d("Activity Life Cycle", "onStop()");
}

@Override
protected void onDestroy() {
super.onDestroy();

Log.d("Activity Life Cycle", "onDestroy()");
}
}
Advertisements