美文网首页
Activity的生命周期

Activity的生命周期

作者: s1991721 | 来源:发表于2018-05-09 13:58 被阅读0次

生命周期

标准流程

由A启动B的流程:
A - onPause
B - onCreate
B - onStart
B - onResume
A - onStop
在B按返回:
B - onPause
A - onRestart
A - onStart
A - onResume
B - onStop
B - onDestroy

前后台切换

保留活动情况

  • onCreate
  • onStart
  • onResume
    Home
  • onPause
  • onSaveInstanceState
  • onStop
    恢复
  • onRestart
  • onStart
  • onResume

不保留活动情况

  • onCreate
  • onStart
  • onResume
    Home
  • onPause
  • onSaveInstanceState
  • onStop
  • onDestroy
    恢复
  • onCreate
  • onStart
  • onRestoreInstanceState 确实被销毁,重新创建才会执行
  • onResume

锁屏

指定方向

  • onCreate
  • onStart
  • onResume
    锁屏
  • onPause
  • onStop
    解锁
  • onRestart
  • onStart
  • onResume

未指定方向

  • onCreate
  • onStart
  • onResume
    锁屏
  • onPause
  • onStop
  • onDestroy
  • onCreate
  • onStart
  • onResume
  • onPause
    解锁
  • onResume
  • onPause
  • onStop
  • onDestroy
  • onCreate
  • onStart
  • onResume

横竖屏切换

由于Android版本不同生命周期会有所不同,我所打的log是Android7.0

无config configChanges="orientation"

发现以上两种生命周期没有变化,再来试试screenSize

configChanges="screenSize"

三种情况完全没差啊,这时

configChanges="orientation|screenSize"

换Android4.4的模拟器看看

无config

没有onConfigurationChanged回调

configChanges="orientation"

还没有onConfigurationChanged回调

configChanges="screenSize"

the same

configChanges="orientation|screenSize"

相关文章

网友评论

      本文标题:Activity的生命周期

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