开发者

Android prevent saving state

how can I disable saving widget's 开发者_如何学编程state from a class that extends specific widget? I need it to behave just like it was newly created.


The easiest way to prevent any View to persist its state is to not assign id to this view (i.e. no android:id="...").


If that is no sufficient and you still need to reference the view, you can use next trick. Override View's onSaveInstanceState() and onRestoreInstanceState() in a following way:

@Override
public Parcelable onSaveInstanceState()
{
    super.onSaveInstanceState();
    return null;
}

@Override
public void onRestoreInstanceState(Parcelable state)
{
    super.onRestoreInstanceState(null);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜