1、

Android生命周期_编写代码

2、

Android生命周期_Android_02

3、

Android生命周期_生命周期_03

4、

Android生命周期_生命周期_04

5、

Android生命周期_编写代码_05

6、

Android生命周期_生命周期_06


二、实现

1、编写代码如下:

package com.example.androidlife;

import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.view.Menu;

public class MainActivity extends Activity {

	public final String TAG = "MainActivity";
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		Log.i(TAG,"onCreate method is executed·········");
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

	@Override
	protected void onRestart() {
		super.onRestart();
		
		Log.i(TAG,"onRestart method is executed·········");
	}
	
	
	@Override
	protected void onResume() {
		super.onResume();
		
		Log.i(TAG,"onResume method is executed·········");
	}
	
	@Override
	protected void onStop() {
		super.onStop();
		
		Log.i(TAG,"onStop method is executed·········");
	}
	
	@Override
	protected void onPause() {
		super.onPause();
		
		Log.i(TAG,"onPause method is executed·········");
	}
	
	@Override
	protected void onDestroy() {
		super.onDestroy();
		
		Log.i(TAG,"onDestroy method is executed·········");
	}
	
	@Override
	protected void onStart() {
		super.onStart();
		
		Log.i(TAG,"onStart method is executed·········");
	}
}



2、新建logcat

   单击

Android生命周期_android_07

,这时你会看到以下界面(对着下图进行配置):

Android生命周期_生命周期_08






3、部署并运行该程序,这时我们可以看到以下结果:

Android生命周期_生命周期_09