Fallback to SharedPreferences$Editor.commit() when no apply() exists.
Gingerbread widened the SharedPreferences.Editor interface, adding an
apply() method. Most people don't implement this interface
themselves, but a couple apps do.
A few spots in the core framework take a SharedPreferences[.Editor]
from apps, which might be a pre-Gingerbread implementation without an
apply() method. This patch makes sure we never depend on the presence
of an apply() method, falling back to commit() if apply() isn't
available.
Change-Id: I32693ac9227a60b694526a26a30234fb17a40581
diff --git a/core/java/android/preference/Preference.java b/core/java/android/preference/Preference.java
index dde6493..36d676a 100644
--- a/core/java/android/preference/Preference.java
+++ b/core/java/android/preference/Preference.java
@@ -1195,7 +1195,14 @@
private void tryCommit(SharedPreferences.Editor editor) {
if (mPreferenceManager.shouldCommit()) {
- editor.apply();
+ try {
+ editor.apply();
+ } catch (AbstractMethodError unused) {
+ // The app injected its own pre-Gingerbread
+ // SharedPreferences.Editor implementation without
+ // an apply method.
+ editor.commit();
+ }
}
}