How to call a function *after* onPreferenceChange?
<p>I'm new to Android development.
In my app, when a user changes a preference, a function should be called to update some variables.</p>

<p>This is my current code:</p>

<pre><code>mypref.setOnPreferenceChangeListener(
   new OnPreferenceChangeListener() {
      public boolean onPreferenceChange(Preference arg0, Object arg1) {
         if(arg1.toString().matches("...") == false) {
            ...
            return false;
         }

         ...

         updateVariables();
         return true;
     }
});
</code></pre>

<p>The problem is that when <code>updateVariables()</code> is called, the preference value is not yet updated and the function sees the old value.</p>

<pre><code>private void updateVariables()
{
    SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
    Map&lt;String, ?&gt; savedKeys = sharedPref.getAll();

    for (Map.Entry&lt;String, ?&gt; entry : savedKeys.entrySet()) {
       // for each preference...
    }
}
</code></pre>

<p>What would the least invasive solution be? Thanks!</p>
