我试图ViewPager
通过在其PagerAdapter
:restoreState()
和saveState()
. 但是,在我的情况下,它们似乎无法正常工作。我做错了什么?
@Override
public Parcelable saveState() {
Bundle bundle = new Bundle();
bundle.putParcelable("instanceState", super.saveState());
bundle.putInt("stateToSave", position);
return bundle;
}
@Override
public void restoreState(Parcelable state, ClassLoader c) {
if (state instanceof Bundle) {
Bundle bundle = (Bundle) state;
position = bundle.getInt("stateToSave");
super.restoreState(bundle.getParcelable("instanceState"), c);
return;
}
super.restoreState(state, c);
}