我有一个扩展 FrameLayout 的自定义 ViewGroup。在方向更改时,我需要保留一个 int 值。我正在覆盖onSaveInstanceState()
and
onRestoreInstanceState(Parcelable state)
以保持旧值。我的代码如下
@Override
protected Parcelable onSaveInstanceState() {
final Bundle bundle = new Bundle();
bundle.putInt(POSITION, position);
return bundle;
}
@Override
protected void onRestoreInstanceState(Parcelable state) {
if (state instanceof Bundle) {
Bundle bundle = (Bundle) state;
mPosition = bundle.getInt(POSITION);
}
super.onRestoreInstanceState(state);
}
但我要崩溃了。
java.lang.IllegalStateException: Derived class did not call super.onSaveInstanceState()
但是,如果我打电话super.onSaveInstanceState()
给onSaveInstanceState
我如何返回我的捆绑价值?
这里有什么问题?
提前致谢!!