Android小笔记Activity生命周期

    Activity生命周期:

        onCreate()创建-----》onStart()开始------》onResume()获取焦点-----》Activityrunning


运行------》onPause()|-页面跳转----》App process killed-----》onCreate()重新创建一个界面;

                     |-失去焦点-------》onStop()|-应用并没有停止按home键回到应用时--

                                                                    --》onRestart()重新开始

                                                |-应用停止----》onDestroy()销毁    


源码:

        

        public class MainActivity extends Activity {

                                                 //

         private static final String TAG = "MainActivity";

        //创建

         @Override

         protected void onCreate(Bundle savedInstanceState) {

         super.onCreate(savedInstanceState);

         setContentView(R.layout.activity_main);

         Log.i(TAG, "oncreate");

        

         }

        //开始

         @Override

         protected void onStart() {

         Log.i(TAG, "onstart");

         super.onStart();

         }

        //获取焦点

         @Override

         protected void onResume() {

         Log.i(TAG, "onresume");

         super.onResume();

         }

        //失去焦点

         @Override

         protected void onPause() {

         Log.i(TAG, "onpasue");

         super.onPause();

         }

        //停止

         @Override

         protected void onStop() {

         Log.i(TAG, "onstop");

         super.onStop();

         }

          

        

        //销毁

         @Override

         protected void onDestroy() {

         Log.i(TAG, "ondestroy");

         super.onDestroy();

         }

        //重新开始

         @Override

         protected void onRestart() {

         Log.i(TAG, "onrestart");

         super.onRestart();

         }

        }


你可能感兴趣的:(生命周期,Activity)