我有一個ViewPager具有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);
}