This issue is mainly related to this:
http://code.google.com/p/android/issues/detail?id=2096
In order to solve it, some things must be done, first, only use string-array in your resource arrays.xml
Code:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="update_freq_options">
<item>Every Minute</item>
<item>5 minutes</item>
<item>10 minutes</item>
<item>15 minutes</item>
<item>Every Hour</item>
</string-array>
<string-array name="magnitudes">
<item>3</item>
<item>5</item>
<item>6</item>
<item>7</item>
<item>8</item>
</string-array>
<string-array name="magnitude_options">
<item>3</item>
<item>5</item>
<item>6</item>
<item>7</item>
<item>8</item>
</string-array>
<string-array name="update_freq_value">
<item>1</item>
<item>5</item>
<item>10</item>
<item>15</item>
<item>60</item>
</string-array>
</resources>
In the Activity Earthquake the method updateFromPreferences should be like this, because using the standard preferences the value selected will be directly returned (and not the index for the array).
Code:
private void updateFromPreferences() {
Context context = getApplicationContext();
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
minimumMagnitude = Integer.parseInt(prefs.getString(Preferences.PREF_MIN_MAG, "0"));
updateFreq = Integer.parseInt(prefs.getString(Preferences.PREF_UPDATE_FREQ, "0"));
autoUpdate = prefs.getBoolean(Preferences.PREF_AUTO_UPDATE, false);
}
Another important change is to delete the requestCode check in the onActivityResult method, because we are returning from the preferences screen using the back functionality and this will return us a RESULT_CANCELED.
Code:
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == SHOW_PREFERENCES)
//if (resultCode == Activity.RESULT_OK) {
updateFromPreferences();
refreshEarthquakes();
//}
}
Applying all this changes the sample will work perfectly.
Only one last issue, if you have already stored preferences as integers the code will fail because they must be cleaned, I am still looking for the way to clean the preferences without having to add a little trick in the code. Just clear the preferences and then commit.