• Does not crash if the user receives a phone call or switches to another app while using your app.
  • Does not consume valuable system resources when the user is not actively using it.
  • Does not lose the user's progress if they leave your app and return to it at a later time.
  • Does not crash or lose the user's progress when the screen rotates between landscape and portrait orientation.
了解生命周期的作用:

1.在用户接电话或者切换到其他应用的时候不崩溃

2.在用户不激活应用的时候,释放系统资源

3.在用户从其他应用回到本应用时,可以记录用户的使用数据(进程)

4.当用户切换显示的时候(横向显示或者纵向显示)不丢失用户数据


Resumed In this state, the activity is in the foreground and the user can interact with it. (Also sometimes referred to as the "running" state.) Paused In this state, the activity is partially obscured by another activity—the other activity that's in the foreground is semi-transparent or doesn't cover the entire screen. The paused activity does not receive user input and cannot execute any code. Stopped In this state, the activity is completely hidden and not visible to the user; it is considered to be in the background. While stopped, the activity instance and all its state information such as member variables is retained, but it cannot execute any code.

 The system calls onDestroy() after it has already called onPause() and onStop() in all situations except one: when you call finish() from within the onCreate() method. In some cases, such as when your activity operates as a temporary decision maker to launch another activity, you might call finish()from within onCreate() to destroy the activity. In this case, the system immediately calls onDestroy()without calling any of the other lifecycle methods.


You should usually use the onPause() callback to:

  • Stop animations or other ongoing actions that could consume CPU.
  • Commit unsaved changes, but only if users expect such changes to be permanently saved when they leave (such as a draft email).
  • Release system resources, such as broadcast receivers, handles to sensors (like GPS), or any resources that may affect battery life while your activity is paused and the user does not need them.

Generally, you should not use onPause() to store user changes (such as personal information entered into a form) to permanent storage. The only time you should persist user changes to permanent storage withinonPause() is when you're certain users expect the changes to be auto-saved (such as when drafting an email). However, you should avoid performing CPU-intensive work during onPause(), such as writing to a database, because it can slow the visible transition to the next activity (you should instead perform heavy-load shutdown operations during onStop()).

更多相关文章

  1. Android 4.0 用户输入子系统
  2. 判断Android的WIFI与GPS状态,并引导用户前去开启GPS与WIFI设置
  3. Android和Java本地数据库新选择
  4. 在Android中查看和管理sqlite数据库
  5. Android图表控件MPAndroidChart——曲线图LineChart(多条曲线)动态
  6. Android联系人数据库全解析(1)
  7. [转」android中的数据库操作
  8. 数据存储和界面展示一
  9. android中的数据库操作ZZ

随机推荐

  1. Android之自定义checkbox样式
  2. Android(安卓)应用程序组件学习
  3. Android驱动程序开发和调试环境配置
  4. Android API demos 阅读笔记 1
  5. Android关于图片压缩
  6. canvas 画一个圆上有 旋转角度 的直线
  7. Mac与Android文件传输工具 Android File
  8. 安卓开发---进度条
  9. android 抽屉效果
  10. 如何进入Android adb shell 命令行模式