Android生命周期

来源:互联网 发布:linux退出账号 编辑:程序博客网 时间:2024/06/05 06:58

1、

2、

3、

4、

5、

6、


二、实现

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";@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);Log.i(TAG,"onCreate method is executed·········");}@Overridepublic 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;}@Overrideprotected void onRestart() {super.onRestart();Log.i(TAG,"onRestart method is executed·········");}@Overrideprotected void onResume() {super.onResume();Log.i(TAG,"onResume method is executed·········");}@Overrideprotected void onStop() {super.onStop();Log.i(TAG,"onStop method is executed·········");}@Overrideprotected void onPause() {super.onPause();Log.i(TAG,"onPause method is executed·········");}@Overrideprotected void onDestroy() {super.onDestroy();Log.i(TAG,"onDestroy method is executed·········");}@Overrideprotected void onStart() {super.onStart();Log.i(TAG,"onStart method is executed·········");}}


2、新建logcat

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




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




原创粉丝点击