How do you refresh PreferenceActivity to show changes in the settings?

Instead of

finish();
startActivity(getIntent());

I prefer the following code :

setPreferenceScreen(null);
addPreferencesFromResource(R.xml.preferences);

This will reset the display as well but without the whole finish procedure and its consequences.
Plus this code works well with PreferenceActivity and PreferenceFragment.

This is interesting if you would like to change dynamically the locale value for example. In this case, working with the manager is not enough because you want a full reload of titles and values.

EDIT: setPreferenceScreen is deprecated in PreferenceActivity (still working) but is not in PreferenceFragment

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)