Android 四大组件之Activity(Activity/Fragment)
本文由 Luzhuo 编写,转发请保留该信息.
原文: http://blog.csdn.net/rozol/article/details/79606158
四大组件(Activity / BroadcastReceiver / Service / ContentProvider)之一
四大组件均运行于主线程
Activity
生命周期
Activity的生命周期种类:
- onCreate // 创建
- onStart // 可见, 无焦点
- onResume // 获得焦点, 此时为前台Activity
- onPause // 失去焦点, 仍可见
- onStop // 不可见, 此时为后台Activity
- onDestroy // 销毁
- onRestart // 重启
Activity的生命周期流程:
/* 打开SecondActivity的生命周期: MainActivity: onPause - - - - - - - -- - - - - -- - - - -> onStop SecondActivity: onCreate -> onStart -> onResume 关闭SecondActivity的生命周期: MainActivity: onStart -> onResume SecondActivity: onPause - - - - - - - - - - -> onStop -> onDestroy 打开ThirdActivity(部分透明)的生命周期 MainActivity: onPause ThirdActivity: onCreate -> onStart -> onResume 关闭ThirdActivity(部分透明)的生命周期 MainActivity: onResume ThirdActivity: onPause - - - - - -> onStop -> onDestroy 切换到Home桌面 MainActivity: onPause -> onStop Home桌面切换回来 MainActivity: onRestart -> onStart -> onResume ThirdActivity(部分透明)切换到Home桌面 MainActivity: onStop ThirdActivity: onPause - - - -> onStop Home桌面切换回ThirdActivity(部分透明) MainActivity: onRestart -> onStart ThirdActivity: onRestart -> onStart -> onResume Activity被kill优先级: onStop(后台进程, 且不可见) > onPause(前台进程, 但无焦点) > running(前台) 多个同级进程, 按LRU算法选择 */