title: Process the value of preference before save in Android?
body: <p>I need to crypt my password before save it to local android database. Everything work fine without encryption, I have preferences.xml and so. How can I call a function <strong>after</strong> I change value of preference (for example, password) ? Here is my code:</p>
  
  <pre><code>public class Preferences extends PreferenceActivity {
      @Override
      protected void onCreate(Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
              addPreferencesFromResource(R.xml.preferences);
  
              // Get the custom preference
              Preference customPref = (Preference) findPreference("pass");
  
              customPref.setOnPreferenceChangeListener(new OnPreferenceChangeListener(){
                  @Override
                  public boolean onPreferenceChange(Preference preference, Object newValue) {
                  String crypto = SimpleCrypto.encrypt("MYSECRETKEY", newValue.toString()); // encrypt
                  // Here is where I'm wrong, I guess.
                  SharedPreferences settings = getSharedPreferences("preferences", MODE_PRIVATE);
                  SharedPreferences.Editor editor = settings.edit();
                  editor.putString("pass", crypto);
                  editor.commit();
              });
      }
  }
  </code></pre>
  
  <p>P.S: Like this, when I change password, it stores password without encryption.</p>