游戏,或者进程中,暂停是,需要报当前ui保存下来,这就是savedInstanceState
所以狠毒时候,我们要if(savedInstanceState !=null){
//写入相应代码
}
当Activty和Fragment被系统或者某些内存清理应用还有默认设置下的横竖屏切换而被销毁时,将会触发onSaveInstanceState(Bundle savedInstanceState)(Fragment被detach时并不会触发此方法),此时可以将要保存的数据放入savedInstanceState中,之后在以下生命周期方法中取得保存的数据
Activiyt.onCreate(Bundle savedInstanceState)
Activiyt.onViewStateRestored(Bundle savedInstanceState)
Fragment.onCreate(Bundle savedInstanceState)
Fragment.onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
Fragment.onActivityCreated(Bundle savedInstanceState)