Activity生命周期

打开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 退出任务栈

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 说实话,之前对应这些基础的东西,我一直以为看一看心中有数就差不多了,可以说是不屑于整理笔记,感觉这种东西应该是看了...
    wt龙阅读 1,814评论 0 0
  • 边做iOS边学Android(一):新建一个project 边做iOS边学Android(二):认识几个常用的控...
    幂琪有天阅读 3,517评论 0 0
  • 转载请注明出处:http://www.jianshu.com/p/1449e3ec2720 生命周期是个老生常谈的...
    landptf阅读 4,121评论 1 3
  • 普通的Activity跳转生命周期变化 MainActivity 启动 D/LUtil: MainActivit...
    AFatty阅读 3,258评论 0 0
  • 娟:为什么谈判的双方不直接表明各自的条件和要求,然后逐一匹配,或者放弃,谈判的效率不会更高吗?为说话非要绕弯呢?许...
    juan子阅读 2,784评论 0 0

友情链接更多精彩内容