Take the 2-minute tour ×

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.

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

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:

public Parcelable onSaveInstanceState()
    return null;

public void onRestoreInstanceState(Parcelable state)
share|improve this answer
Those 2 functions are public, not protected. I've already tried overriding onRestoreInstanceState before. It crashes and the logcat says that's because I didn't call the super function. Anyway, what should I return in onSaveInstance state? –  Sebastian Nowak Aug 30 '11 at 18:42
I've copied function prototypes from documentation, and they were protected there. But you're right, they are public. Also I've updated the answer and now I tested it, it should work. Sorry for misleading the first time. –  inazaruk Aug 30 '11 at 19:28
Thank you, overriding these functions did the trick. –  Sebastian Nowak Aug 30 '11 at 19:41
add comment

Your Answer


