onSaveInstanceState没有调用writeToParcel

时间:2013-03-01 11:26:44

标签: android android-view

我正在尝试创建一个可以保存状态的自定义视图。当我试图旋转它时,它调用onSaveInstanceState但从不调用writeToParcel。

这是onSaveInstanceState:

@Override
public Parcelable onSaveInstanceState()
{
    Logger.d("On Save Instance State");

    Parcelable superState = super.onSaveInstanceState();

    PictureItemState pis = new PictureItemState(superState);

    for (PictureItem item : mImageList)
    {
        if (!item.isButton)
        {
            pis.mUriList.add(item.uri.toString());
            pis.mIndexList.add(item.index);
        }
    }

    return pis;
}

这是实现writeToParcel的状态类:

static class PictureItemState extends BaseSavedState
{
...    
@Override
    public void writeToParcel(Parcel dest, int flags)
    {
        super.writeToParcel(dest, flags);

        Logger.d("Write to parcel");

        int size = mUriList.size();

        dest.writeInt(size);

        for (int i = 0; i < size; i++)
        {
            dest.writeString(mUriList.get(i));
            dest.writeInt(mIndexList.get(i));
        }
    }
...
}

0 个答案:

没有答案