Android的关键的持久数据应该在onPause()方法中保存
2011-07-03 17:54
519 查看
最近在看Android开发文档,摘录一些关键的段落,方便查找记忆。
Because
Note: Because
关键的持久数据应该在onPause()方法中保存,因为onPause()方法是进程被杀死之前保证会执行的最后一个方法。当然保存的数据必须慎重,因为如果方法阻塞,会影响系统响应时间,影响用户体验。
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()方法是进程被杀死之前保证会执行的最后一个方法。当然保存的数据必须慎重,因为如果方法阻塞,会影响系统响应时间,影响用户体验。
相关文章推荐
- Android开发中保存数据的四种方法方法
- android用存到缓存的方法来保存ListView里的数据
- Android中保存数据常用的方法
- Android开发中保存数据的四种方法方法
- 登录界面跳转,同时将onpause();方法中的保存的数据传到第二个页面
- Android四种保存数据的方法
- Android意外情况(来电话,按Home键,内存不足)保存数据的方法
- Android开发中保存数据的四种方法
- Android中activity保存状态和数据到底该在哪个方法中进行
- Android保存数据几种常用方法解析
- Android中保存数据的四种方法
- 【Android面试】(一):Android中activity保存状态和数据到底该在哪个方法中进行
- android保存数据的方法
- android 转屏时的数据保存方法
- Android数据存储:获取网络图片把图片保存到SD卡中并从SDk卡中读取(通过Bitmap方法)
- Android中保存数据常用的方法
- Android开发中保存数据的四种方法方法
- Android 保存数据的四种方法
- Android保存数据的三种方法
- Android采用File形式保存与读取数据的方法