我有一个带有 WebViews 的 ViewPager 片段。当我旋转手机时,ViewPager 会显示第一页。这是因为活动和片段被再次创建。如何保存 ViewPager 的状态。以下代码不起作用
@Override
public void onActivityCreated(Bundle savedInstanceState)
{
super.onActivityCreated(savedInstanceState);
if (savedInstanceState != null)
{
// Restore last state for checked position.
int pos = savedInstanceState.getInt("currentPosition");
this.setSelectedItem(pos);
}
}
@Override
public void onSaveInstanceState(Bundle outState)
{
super.onSaveInstanceState(outState);
outState.putInt("currentPosition", positionOfSelectedIndex);
}