对一些资源以及状态的操作保存,最好是保存在生命周期的哪个函数中进行
A、onPause() B、onCreate() C、 onResume() D、onStart()
网上所有的答案都是 D 我们头非说是A。 我纠结了。求详细解答。详细

解决方案 »

  1.   

    onPause。因为你如果在onStart中保存,有可能会丢失状态,比如说:你开了一个activity后弹出一个对话框,然后又关闭这个对话框。这时候activity的生命周期是:onPause->onResume,根本没有执行onStart,如果你在onStart中保存,状态就丢失了,但是无论怎样onPause都会执行,所以是onPause。
      

  2.   

    onPause,
    有些东西,百度不一定正确,要靠自己的理解。
      

  3.   

    onStart,告诉你们头activity的生命周期中有个方法叫onRestoreInstanceState
    文档这么说的This method is called after onStart() when the activity is being re-initialized from a previously saved state, given here in savedInstanceState. Most implementations will simply use onCreate(Bundle) to restore their state, but it is sometimes convenient to do it here after all of the initialization has been done or to allow subclasses to decide whether to use your default implementation. The default implementation of this method performs a restore of any view state that had previously been frozen by onSaveInstanceState(Bundle). 
      

  4.   

    我是在onPause,你退出activity的时候他先onPause()再onDestory啊。