@Override
  public void onResume() {
    super.onResume();

    if (mFirstResume) {
      if (mIcicle == null) {
        if (DBG) Log.d(LOG_TAG, "start to init ");
        mPreferences.get(mInitIndex).init(this, false, mSubId);
      } else {
        mInitIndex = mPreferences.size();

        for (CallForwardEditPreference pref : mPreferences) {
          Bundle bundle = mIcicle.getParcelable(pref.getKey());
          pref.setToggled(bundle.getBoolean(KEY_TOGGLE));
          CallForwardInfo cf = new CallForwardInfo();
          cf.number = bundle.getString(KEY_NUMBER);
          cf.status = bundle.getInt(KEY_STATUS);
          pref.handleCallForwardResult(cf);
          pref.init(this, true, mSubId);
        }
      }
      mFirstResume = false;
      mIcicle = null;
    }
  }
  @Override
  public void onFinished(Preference preference, boolean reading) {
    if (mInitIndex < mPreferences.size() - 1 && !isFinishing()) {
      mInitIndex++;
      mPreferences.get(mInitIndex).init(this, false, mSubId);
    }

    super.onFinished(preference, reading);
  }
  @Override
  protected void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);

    for (CallForwardEditPreference pref : mPreferences) {
      Bundle bundle = new Bundle();
      bundle.putBoolean(KEY_TOGGLE, pref.isToggled());
      if (pref.callForwardInfo != null) {
        bundle.putString(KEY_NUMBER, pref.callForwardInfo.number);
        bundle.putInt(KEY_STATUS, pref.callForwardInfo.status);
      }
      outState.putParcelable(pref.getKey(), bundle);
    }
  }
  @Override
  protected void onCreate(Bundle icicle) {
    super.onCreate(icicle);

    mSubId = getIntent().getIntExtra(CallSettingOptions.SUB_ID, 0);
    addPreferencesFromResource(R.xml.videophone_callforward_options);
    if (PhoneFactory.getPhoneCount() > 1) {
      if (mSubId == 0) {
        setTitle(
            getResources().getString(R.string.sim1)
                + getResources().getString(R.string.videophone_callforward_setting_title));
      } else if (mSubId == 1) {
        setTitle(
            getResources().getString(R.string.sim2)
                + getResources().getString(R.string.videophone_callforward_setting_title));
      }
    }
    PreferenceScreen prefSet = getPreferenceScreen();
    mButtonCFU = (CallForwardEditPreference) prefSet.findPreference(BUTTON_CFU_KEY);
    mButtonCFB = (CallForwardEditPreference) prefSet.findPreference(BUTTON_CFB_KEY);
    mButtonCFNRy = (CallForwardEditPreference) prefSet.findPreference(BUTTON_CFNRY_KEY);
    mButtonCFNRc = (CallForwardEditPreference) prefSet.findPreference(BUTTON_CFNRC_KEY);

    mButtonCFU.setParentActivity(this, mButtonCFU.reason);
    mButtonCFB.setParentActivity(this, mButtonCFB.reason);
    mButtonCFNRy.setParentActivity(this, mButtonCFNRy.reason);
    mButtonCFNRc.setParentActivity(this, mButtonCFNRc.reason);

    mPreferences.add(mButtonCFU);
    mPreferences.add(mButtonCFB);
    mPreferences.add(mButtonCFNRy);
    mPreferences.add(mButtonCFNRc);

    // we wait to do the initialization until onResume so that the
    // TimeConsumingPreferenceActivity dialog can display as it
    // relies on onResume / onPause to maintain its foreground state.

    mFirstResume = true;
    mIcicle = icicle;
  }