Activity(View)的存储与恢复

来源:互联网 发布:ae软件怎么下载 编辑:程序博客网 时间:2024/04/30 09:50
@Override    protected Parcelable onSaveInstanceState() {        // TODO Auto-generated method stub        Bundle bundle = new Bundle();        bundle.putParcelable(Instance, super.onSaveInstanceState());        bundle.putBoolean(Instance_GameOver, IsGameOver);        bundle.putParcelableArrayList(Instance_WhiteArray, whiteArray);        bundle.putParcelableArrayList(Instance_BlackArray, blackArray);        return bundle;    }    @Override    protected void onRestoreInstanceState(Parcelable state) {        // TODO Auto-generated method stub        if(state instanceof Bundle)        {            Bundle bundle=(Bundle) state;            IsGameOver=bundle.getBoolean(Instance_GameOver);            whiteArray=bundle.getParcelableArrayList(Instance_WhiteArray);            blackArray=bundle.getParcelableArrayList(Instance_BlackArray);            super.onRestoreInstanceState(bundle.getParcelable(Instance));            return ;        }        super.onRestoreInstanceState(state);    }

在打电话或者翻转屏幕可能会清空view,调用这两个方法,只需要改动里面内容即可恢复与保存。

原创粉丝点击