恢復實例狀態這裏是我的代碼:保存和與片段
@Override
public void onSaveInstanceState(Bundle savedInstanceStateBundle)
{
savedInstanceStateBundle.putInt(AVERAGE_SESSION_VALUE_HOLDER, averageSessionSeek.getProgress());
savedInstanceStateBundle.putInt(CONFIDENCE_VALUE_HOLDER, confidenceSeek.getProgress());
savedInstanceStateBundle.putInt(CONVERSION_TIME_VALUE_HOLDER, conersionTimeSeek.getProgress());
}
上面的代碼屬於InputFragment.java
延伸Fragment
。上述方法保存了實例的狀態,因此當用戶離開特定的Fragment
並返回時,實例將被恢復。我試着用下面的代碼
@Override
public void onRestoreInstanceState(Bundle savedInstanceStateBundle)
{
}
但它失敗了,編譯錯誤。那麼,如何在Fragments
中重新加載實例狀態?
那麼我應該把恢復代碼放在哪裏? –
in onActivityCreated(Bundle),see http://developer.android.com/reference/android/app/Fragment.html#onActivityCreated(android.os.Bundle) – Melquiades