标签:
onSaveInstanceState()以及onRestoreInstanceState()
Activity完整的生命周期 onCreate()
–> onStart()
–>onRestoreInstanceState()
–> onResume()
–>onSaveInstanceState()
–> onPause()
–> onStop()
–>onDestroy()
有关 onSaveInstanceState 以 及onRestoreInstanceState 这两个方法我们都知道是用于Activity
销毁和重建时数据的保存。
Activity
,系统不会执行 onSaveInstanceState 。Activity
并没有销毁重建,所以这时候就不会去调用 onRestoreInstanceState 。Activity
中,如果进行横竖屏切换的时候系统会销毁并且重新创建Activity
,这时候系统就会执行 onSaveInstanceState 以及 onRestoreInstanceState ,因为这是系统把Activity
给销毁了,系统要负责就执行这两个方法来给你保存和恢复数据。标签:
原文地址:http://www.cnblogs.com/huangzx/p/4465561.html