Activity 黑屏问题.md

昨天公司app遇到个黑屏问题,温习一把生命周期,基础还是最重要的

  • 正常activity启动生命周期
/com.example.a9_7acticitylifecycle I/faceWuActivity1: onCreate
/com.example.a9_7acticitylifecycle I/faceWuActivity1: onStart
/com.example.a9_7acticitylifecycle I/faceWuActivity1: onResume
/com.example.a9_7acticitylifecycle I/faceWuActivity1: onAttachedToWindow
/com.example.a9_7acticitylifecycle I/faceWuActivity1: onWindowFocusChanged//可见可交互
/com.example.a9_7acticitylifecycle I/faceWuActivity1: onWindowFocusChanged
/com.example.a9_7acticitylifecycle I/faceWuActivity1: onPause
/com.example.a9_7acticitylifecycle I/faceWuActivity1: onStop//完全不可见,不可见
/com.example.a9_7acticitylifecycle I/faceWuActivity1: onDestroy

  • 在一个Activity onCreate 启动另一个activity,两者都是全屏,两者的生命周期会是怎么样呢
    即使是在onCreate启动,页面1依然会走到onAttachedToWindow,因丢失焦点无法执行到onWindowFocusChanged;最后页面会执行到onStop完全不可见,不可交互
/? I/faceWuActivity1: onCreate
/? I/faceWuActivity1: onStart
/? I/faceWuActivity1: onResume
/? I/faceWuActivity1: onPause
/? I/faceWuActivity1: onAttachedToWindow
/? I/faceWuActivity2: onCreate
/? I/faceWuActivity2: onStart
/? I/faceWuActivity2: onResume
/? I/faceWuActivity2: onAttachedToWindow
/? I/faceWuActivity2: onWindowFocusChanged
/? I/faceWuActivity1: onStop
/com.example.a9_7acticitylifecycle I/faceWuActivity2: onPause
/com.example.a9_7acticitylifecycle I/faceWuActivity1: onRestart
/com.example.a9_7acticitylifecycle I/faceWuActivity1: onStart
/com.example.a9_7acticitylifecycle I/faceWuActivity1: onResume
/com.example.a9_7acticitylifecycle I/faceWuActivity1: onWindowFocusChanged
/com.example.a9_7acticitylifecycle I/faceWuActivity2: onWindowFocusChanged
/com.example.a9_7acticitylifecycle I/faceWuActivity2: onStop
/com.example.a9_7acticitylifecycle I/faceWuActivity2: onDestroy

  • 在一个Activity onCreate 启动另一个activity,后者不是全屏,两者的生命周期会是怎么样呢
    即使是在onCreate启动,页面1依然会走到onAttachedToWindow;但不会执行onStop,因为页面2不是全屏,页面1处于部分可见的状态
/com.example.a9_7acticitylifecycle I/faceWuActivity1: onCreate
/com.example.a9_7acticitylifecycle I/faceWuActivity1: onStart
/com.example.a9_7acticitylifecycle I/faceWuActivity1: onResume
/com.example.a9_7acticitylifecycle I/faceWuActivity1: onPause
/com.example.a9_7acticitylifecycle I/faceWuActivity1: onAttachedToWindow
/com.example.a9_7acticitylifecycle I/faceWuActivity2: onCreate
/com.example.a9_7acticitylifecycle I/faceWuActivity2: onStart
/com.example.a9_7acticitylifecycle I/faceWuActivity2: onResume
/com.example.a9_7acticitylifecycle I/faceWuActivity2: onAttachedToWindow
/com.example.a9_7acticitylifecycle I/faceWuActivity2: onWindowFocusChanged
/com.example.a9_7acticitylifecycle I/faceWuActivity2: onPause
/com.example.a9_7acticitylifecycle I/faceWuActivity1: onResume
/com.example.a9_7acticitylifecycle I/faceWuActivity1: onWindowFocusChanged
/com.example.a9_7acticitylifecycle I/faceWuActivity2: onWindowFocusChanged
/com.example.a9_7acticitylifecycle I/faceWuActivity2: onStop
/com.example.a9_7acticitylifecycle I/faceWuActivity2: onDestroy
  • 现在的启动方式是这样的:

页面1 onCreate中启动页面2,同时弹一个activity类型的弹框3;现象就是页面3在最上面,页面2接着,最后是页面1;页面2是一个广告页,3s后自己会finish;最终的现象是,页面2 finish后,页面3可见,但后面出现黑屏。

09-07 20:20:57.889 16278-16278/? I/faceWuActivity1: onCreate
09-07 20:20:58.035 16278-16278/? I/faceWuActivity1: onStart
09-07 20:20:58.035 16278-16278/? I/faceWuActivity1: onResume
09-07 20:20:58.102 16278-16278/? I/faceWuActivity1: onPause
09-07 20:20:58.108 16278-16278/? I/faceWuActivity3: onCreate
09-07 20:20:58.146 16278-16278/? I/faceWuActivity3: onStart
09-07 20:20:58.147 16278-16278/? I/faceWuActivity3: onResume
09-07 20:20:58.152 16278-16278/? I/faceWuActivity3: onPause
09-07 20:20:58.154 16278-16278/? I/faceWuActivity2: onCreate
09-07 20:20:58.220 16278-16278/? I/faceWuActivity2: onStart
09-07 20:20:58.220 16278-16278/? I/faceWuActivity2: onResume
09-07 20:20:58.224 16278-16278/? I/faceWuActivity2: onPause
09-07 20:20:58.225 16278-16278/? I/faceWuActivity1: onStop
09-07 20:20:58.226 16278-16278/? I/faceWuActivity1: onAttachedToWindow
09-07 20:20:58.229 16278-16278/? I/faceWuActivity3: onAttachedToWindow
09-07 20:20:58.294 16278-16278/? I/faceWuActivity2: onAttachedToWindow
09-07 20:20:58.360 16278-16278/? I/faceWuActivity3: onResume
09-07 20:20:58.381 16278-16278/? I/faceWuActivity3: onWindowFocusChanged
/com.example.a9_7acticitylifecycle I/faceWuActivity2: onStop
/com.example.a9_7acticitylifecycle I/faceWuActivity2: onDestroy

黑屏原因是,页面2 finsh后,页面3还存在,页面1依然停留在onStop状态,不可见

你可能感兴趣的:(Activity 黑屏问题.md)