PreferenceScreen persisted value and load order problem
<p>My problem is a little complicated, so let me explain it using example:</p>

<p>We have PreferenceScreen with two preferences - MyEditTextPreference (ET), which is EditTextPreferencs that in summary shows its current value, and CheckBoxPreference (CB) that defines if ET should display in summary its current value or some other default one. Both preferences persist their values.</p>

<p>Desired behaviors:</p>

<ol>
<li>No persisted values - some "empty text" in ET and unchecked CB
Persisted values - </li>
<li>CB is off - ET displays persisted text. ET is enabled.</li>
<li>CB is on - ET displays default text, still maintaing persisted one. ET is disabled</li>
</ol>

<p>Problem lays in situation 2 - as I am disabling and setting ET text in Main onCreate method, ET's onAttachedActivity method is called later.</p>

<p>Is there any PreferenceScreen (Main) methods that gets called after all its preferences are created? In Preference onAttachedActivity method seems to be the first one that lets to getPersistedString (earlier it states that no value is persisted), yet it is still called after all the PreferenceScreen methods that I tried out...</p>

<p>Below is my sample code
MyEditPreference:</p>

<pre><code>@Override
protected void onAttachedToActivity() {
    mText = getPersistedString("No persisted string");
    updateSummary();
    super.onAttachedToActivity();
}

@Override
protected void onDialogClosed(boolean positiveResult) {
    if (positiveResult) {
        mText = getEditText().getText().toString();
        if (shouldPersist()) persistString(mText);
        updateSummary();
    }
}

public void updateSummary() {
    setSummary(mText);
}

public void updateSummary(String text) {
    setSummary(text);
}
</code></pre>

<p>Main</p>

<pre><code>@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.pref_screen);
    setContentView(R.layout.main);

    mEditTextPreference = (MyEditTextPreference) findPreference("EditTextKey");
    mCheckBoxPreference = (CheckBoxPreference) findPreference("CheckBoxKey");

    mCheckBoxPreference
            .setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

                @Override
                public boolean onPreferenceChange(Preference preference,
                        Object newValue) {
                    checkBoxChanged((Boolean) newValue);
                    return true;
                }
            });


    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
    mCheckBoxPreference.setChecked(prefs.getBoolean("CheckBoxKey", false));
    checkBoxChanged(prefs.getBoolean("CheckBoxKey", false));
}

private void checkBoxChanged(boolean checked) {
    if(checked){
        mEditTextPreference.setEnabled(false);
        mEditTextPreference.updateSummary("Some DEF value");
    } else {
        mEditTextPreference.setEnabled(true);
        mEditTextPreference.updateSummary();
    }
}
</code></pre>
