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);
}
精彩评论