add/remove preference does not work

view story

http://stackoverflow.com – I'm adding and removing preferences using (preference_screen).removePreference(preference) in preferenceFragment. The changes don't reflect until I close and then open the activity that contains the preferenceFragment. Any idea why this happens? this is the preference fragment: public class Settings extends PreferenceFragment{ PreferenceScreen general; preference brightness; boolean shouldHide = false; @Override public void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences) general = (Preferenc (HowTos)