美文网首页
Activity生命周期

Activity生命周期

作者: 一蓑烟雨_8a41 | 来源:发表于2017-12-13 14:52 被阅读0次

打开MainActivity在其中点击按钮,进入BAactivity,然后再退出。代码如下

packagecom.example.liuping.myapplication;

importandroid.content.Intent;

importandroid.support.v7.app.AppCompatActivity;

importandroid.os.Bundle;

importandroid.util.Log;

importandroid.view.View;

public classMainActivityextendsAppCompatActivity {

private static finalStringTAG= MainActivity.class.getSimpleName();

@Override

protected voidonCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

Log.e(TAG,"onCreate---"+TAG);

}

@Override

protected voidonStart() {

super.onStart();

Log.e(TAG,"onStart---"+TAG);

}

@Override

protected voidonResume() {

super.onResume();

Log.e(TAG,"onResume---"+TAG);

}

@Override

protected voidonRestart() {

super.onRestart();

Log.e(TAG,"onRestart---"+TAG);

}

@Override

protected voidonRestoreInstanceState(Bundle savedInstanceState) {

super.onRestoreInstanceState(savedInstanceState);

Log.e(TAG,"onRestoreInstanceState---"+TAG);

}

@Override

protected voidonPause() {

super.onPause();

Log.e(TAG,"onPause---"+TAG);

}

@Override

protected voidonStop() {

super.onStop();

Log.e(TAG,"onStop---"+TAG);

}

@Override

protected voidonDestroy() {

super.onDestroy();

Log.e(TAG,"onDestroy---"+TAG);

}

public voidgoB(View view) {

Intent intent=newIntent(this,BActivity.class);

startActivity(intent);

}

}

结果如下:

12-13 06:16:06.996 27955-27962/? E/zygote: Failed sending reply to debugger: Broken pipe

12-13 06:16:07.964 27955-27955/? E/MainActivity: onCreate---MainActivity

12-13 06:16:07.967 27955-27955/? E/MainActivity: onStart---MainActivity

12-13 06:16:07.970 27955-27955/? E/MainActivity: onResume---MainActivity

12-13 06:16:08.106 27955-27995/com.example.liuping.myapplication E/eglCodecCommon: glUtilsParamSize: unknow param 0x00008cdf

12-13 06:16:08.106 27955-27995/com.example.liuping.myapplication E/eglCodecCommon: glUtilsParamSize: unknow param 0x00008cdf

12-13 06:16:08.108 27955-27995/com.example.liuping.myapplication E/eglCodecCommon: glUtilsParamSize: unknow param 0x00008824

12-13 06:16:08.109 27955-27995/com.example.liuping.myapplication E/eglCodecCommon: glUtilsParamSize: unknow param 0x00008824

12-13 06:16:21.245 27955-27955/com.example.liuping.myapplication E/MainActivity: onPause---MainActivity

12-13 06:16:21.283 27955-27955/com.example.liuping.myapplication E/BActivity: onCreate---BActivity

12-13 06:16:21.284 27955-27955/com.example.liuping.myapplication E/BActivity: onStart---BActivity

12-13 06:16:21.287 27955-27955/com.example.liuping.myapplication E/BActivity: onResume---BActivity

12-13 06:16:21.815 27955-27955/com.example.liuping.myapplication E/MainActivity: onStop---MainActivity

12-13 06:17:13.864 27955-27955/com.example.liuping.myapplication E/BActivity: onPause---BActivity

12-13 06:17:13.879 27955-27955/com.example.liuping.myapplication E/MainActivity: onRestart---MainActivity

12-13 06:17:13.879 27955-27955/com.example.liuping.myapplication E/MainActivity: onStart---MainActivity

12-13 06:17:13.880 27955-27955/com.example.liuping.myapplication E/MainActivity: onResume---MainActivity

12-13 06:17:14.258 27955-27955/com.example.liuping.myapplication E/BActivity: onStop---BActivity

12-13 06:17:14.259 27955-27955/com.example.liuping.myapplication E/BActivity: onDestroy---BActivity

a:oncreate   onstart onresume  

点击跳转:a:onpause 

b:oncreate on start onresume

a :onstop  a压入activity栈

点击返回:b:onpause

a:onrestart 弹出栈  onstart onresume

b:onstop ondestory 退出任务栈

相关文章

网友评论

      本文标题:Activity生命周期

      本文链接:https://www.haomeiwen.com/subject/yzwaixtx.html