Activity life cycle
来源:互联网 发布:淘宝黄牛怎么举报 编辑:程序博客网 时间:2024/05/21 10:46
1. Key life cyle: onCreate(Bundle savedBundleInstance) -> onStart()-> onResume() -> onPause() -> onStop() -> onDestory()
2. Save status: there are two methods you can use to save state:
* onSaveInstanceState(Bundle outInstanceState...): this method will be called when the activity is destroyed by system, such as when you rotate screen, or when memory is low and the activity is destroyed to save resource. Normally, you should save temporary state of activity information.
* onPause(): this method will be called when user try to destroy the activity, such as press "BACK" button. And as you can see, there is no bundle parameter, so with this method, you should save information that you want to persist (save in file)
3. Get back saved status: there are two method you can use to get back saved status when the activity is resnumed
* onCreate(Bundle savedInstance): the savedInstance parameter is the parameter saved by onSaveInstanceState(), so you can get back status. Of cause, you can also get back status persisted by onPause(), since the file is always available.
* onRestoreInstanceState(Bundle savedInstanceState): the savedInstanceState is also saved by onSaveInstanceState(), so you can get back status. Of cause, you can also get back status persisted by onPause(), since the file is always available.
* onCreate(Bundle savedInstance): the savedInstance parameter is the parameter saved by onSaveInstanceState(), so you can get back status. Of cause, you can also get back status persisted by onPause(), since the file is always available.
* onRestoreInstanceState(Bundle savedInstanceState): the savedInstanceState is also saved by onSaveInstanceState(), so you can get back status. Of cause, you can also get back status persisted by onPause(), since the file is always available.
4. When will onSavedInstanceState() be called:
* Press Home Button
* Press Power Button
* Start a new activity from old activity, the old activity's onSavedInstanceState() will be called
* Rotate screen
* Press Home Button
* Press Power Button
* Start a new activity from old activity, the old activity's onSavedInstanceState() will be called
* Rotate screen
5. When will onPause() be called: before activity fall into Paused status
6. When will onRestoreSavedInstance() be called: when the activity is destroyed by system, such as rotate screen. (if you press Home button, and go back to the activity quickly, the system will quite likely to destroy the activity, in this case, the onRestoreSavedInstance() will not be called)
6. When will onRestoreSavedInstance() be called: when the activity is destroyed by system, such as rotate screen. (if you press Home button, and go back to the activity quickly, the system will quite likely to destroy the activity, in this case, the onRestoreSavedInstance() will not be called)
0 0
- Activity life cycle
- Android Activity life Cycle
- Activity life cycle
- Android activity‘s life cycle
- Android四大组件之Activity Life Cycle
- Android Activity深入分析-Activity Life Cycle Callback
- activity life cycle 和fragment life cycle(面试题常考)
- Android Activity Life Cycle - What are all these methods for?
- <Android> Activity 和 Fragment 信息传递? Activity 和 Fragment 的 Life cycle?
- Servlet life cycle
- Software Development Life-Cycle
- UIComponent之life cycle
- Bug life cycle
- Life Cycle of Object
- Life Cycle of Threads
- Flex Component Life Cycle
- !!!Software release life cycle
- Software release life cycle
- 电影节——并查集
- Java常用基本字符串函数
- DAX-PowerBI系列
- Date与Calendar类
- JS中的call()和apply()方法
- Activity life cycle
- 279. Perfect Squares
- 八皇后与回溯法
- 中央巡视组进驻北京大学,袁萌为何鸣冤?有何根据?
- 初级前端程序员必备干货!
- 单例模式的三种方法
- LeetCode #169: Majority Element
- windows 下 select 配合socket实现多路复用
- 一天一算法:day01二叉树打印练习