summaryrefslogtreecommitdiffstats
path: root/core/java/android/content/SharedPreferences.java
diff options
context:
space:
mode:
authorBrad Fitzpatrick <bradfitz@android.com>2010-10-10 10:58:47 -0700
committerBrad Fitzpatrick <bradfitz@android.com>2010-10-10 15:26:24 -0700
commitdd644c179c1bf47d82d776d7f644e4fc1467159d (patch)
treed566c1c17f2b325e3760a34ca10cf71d965893f2 /core/java/android/content/SharedPreferences.java
parent4e1658afb8a79aa03a5ca712b02b2a33fb00bf6d (diff)
downloadframeworks_base-dd644c179c1bf47d82d776d7f644e4fc1467159d.zip
frameworks_base-dd644c179c1bf47d82d776d7f644e4fc1467159d.tar.gz
frameworks_base-dd644c179c1bf47d82d776d7f644e4fc1467159d.tar.bz2
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
Diffstat (limited to 'core/java/android/content/SharedPreferences.java')
-rw-r--r--core/java/android/content/SharedPreferences.java18
1 files changed, 15 insertions, 3 deletions
diff --git a/core/java/android/content/SharedPreferences.java b/core/java/android/content/SharedPreferences.java
index 1484204..3221afa 100644
--- a/core/java/android/content/SharedPreferences.java
+++ b/core/java/android/content/SharedPreferences.java
@@ -186,9 +186,21 @@ public interface SharedPreferences {
* {@link #commit} will block until all async commits are
* completed as well as the commit itself.
*
- * <p>If you call this from an {@link android.app.Activity},
- * the base class will wait for any async commits to finish in
- * its {@link android.app.Activity#onPause}.</p>
+ * <p>As {@link SharedPreferences} instances are singletons within
+ * a process, it's safe to replace any instance of {@link #commit} with
+ * {@link #apply} if you were already ignoring the return value.
+ *
+ * <p>You don't need to worry about Android component
+ * lifecycles and their interaction with <code>apply()</code>
+ * writing to disk. The framework makes sure in-flight disk
+ * writes from <code>apply()</code> complete before switching
+ * states.
+ *
+ * <p class='note'>The SharedPreferences.Editor interface
+ * isn't expected to be implemented directly. However, if you
+ * previously did implement it and are now getting errors
+ * about missing <code>apply()</code>, you can simply call
+ * {@link #commit} from <code>apply()</code>.
*/
void apply();
}