最近在看Android开发文档,摘录一些关键的段落,方便查找记忆。

Because onPause() is the first of the three(onPause(),onStop(),onDestroy()), once the activity is created, onPause() is the last method that's guaranteed to be called before the process can be killed—if the system must recover memory in an emergency, then onStop() and onDestroy() might not be called. Therefore, you should use onPause() to write crucial persistent data (such as user edits) to storage. However, you should be selective about what information must be retained during onPause(), because any blocking procedures in this method block the transition to the next activity and slow the user experience.

Note: Because onSaveInstanceState() is not guaranteed to be called, you should use it only to record the transient state of the activity (the state of the UI)—you should never use it to store persistent data. Instead, you should use onPause() to store persistent data (such as data that should be saved to a database) when the user leaves the activity.

    关键的持久数据应该在onPause()方法中保存,因为onPause()方法是进程被杀死之前保证会执行的最后一个方法。当然保存的数据必须慎重,因为如果方法阻塞,会影响系统响应时间,影响用户体验。

更多相关文章

  1. 【面试】Android Retrofit+Rxjava 如何实现同时请求多个接口数据
  2. Android添加单元测试的方法与步骤
  3. Android Studio无法执行Java类的main方法问题及解决方法
  4. Android获取屏幕宽度的4种方法
  5. android 建数据库 SQLite 存储sd 卡或者内存
  6. android 开发收银系统,弹出键盘固定界面UI的方法
  7. Android优质学习方法
  8. Android应用程序组件Content Provider的共享数据更新通知机制分
  9. Android TextView各种使用方法

随机推荐

  1. android之R cannot be resolved to a var
  2. Android Studio中解决Gradle DSL method
  3. android pppd拨号问题及解决办法
  4. Android Studio如何集成Genymotion
  5. android的logcat详细用法zt
  6. 【Android】EventBus源码解析(3.1.1)
  7. Android Map库
  8. 今日签到
  9. android Fragments (Android官方文档中文
  10. Dalvik虚拟机和ART(Android(安卓)RunTime