我有一个扩展 LinearLayout 的自定义视图。我已经实现了 onSaveInstanceState() 和 onRestoreInstanceState() 来保存当前的视图状态。然而,没有采取任何行动。当我在这两种方法中放置日志时,Log Cat 中也没有出现任何内容。我假设这两种方法甚至都没有被调用。谁能解释问题出在哪里?谢谢。
@Override
public Parcelable onSaveInstanceState() {
Bundle bundle = new Bundle();
bundle.putParcelable("instanceState", super.onSaveInstanceState());
bundle.putInt("currentPage", currentPage);
return bundle;
}
@Override
public void onRestoreInstanceState(Parcelable state) {
if (state instanceof Bundle) {
Bundle bundle = (Bundle) state;
currentPage = bundle.getInt("currentPage");
Log.d("State", currentPage + "");
super.onRestoreInstanceState(bundle.getParcelable("instanceState"));
return;
}
super.onRestoreInstanceState(state);
}