Must I persist Activity data when onStop() fires?

不羁的心 提交于 2019-12-24 00:34:30

问题


I find the official documentation regarding the Activity lifecycle unclear. It's littered with words such as should and might which makes me wonder what I must. When it comes to the onStop()-method, the documentation says the following:

Note: Because the system retains your Activity instance in system memory when it is stopped, it's possible that you don't need to implement the onStop() and onRestart() (or even onStart() methods at all.

It's possible? Do I or do I not? Lets say I have some custom components that rely on some standard Java objects defined as private variables in the Activity class. Do I need to persist these objects in the onStop-method? Can I be guaranteed that these variables have the same content when on onRestart() fires?

edit: link to table referred to in answer.


回答1:


For your specific question, you need to consider the killable column in the overview table. Android (pre-Honeycomb) considers your Activity killable after onPause() has been called. So if you need persistence for the next call, and you want to handle that on the Activity level, that's where you save your activity state.



来源:https://stackoverflow.com/questions/14443332/must-i-persist-activity-data-when-onstop-fires

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!