>From the SharedPreferences.Editor Documentation: > Unlike commit(), which writes its preferences out to persistent storage > synchronously, apply() commits its changes to the in-memory > SharedPreferences immediately but starts an asynchronous commit to disk and > you won't be notified of any failures. If another editor on this > SharedPreferences does a regular commit() while a apply() is still > outstanding, the commit() will block until all async commits are completed > as well as the commit itself. > > As SharedPreferences instances are singletons within a process, it's safe to > replace any instance of commit() with apply() if you were already ignoring > the return value. > > 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 apply(), you can simply call commit() from apply().
Since apply() was added in Android 2.3, we can start using it where appropriate. I think that means: 1. Wherever we currently call commit(), but don't check a return value. 2. Wherever we do not need to be absolutely sure the values are written to disk ASAP. 3. We mostly use the background thread when using commit(). In places where we are only using the background thread to get commit() off the main thread, we can stop using the background thread altogether. 4. We should switch to apply() even when requiring the background thread so we can get the thread on to the next task faster. I filed bug 1061430 [2] and landed several patches already. There is still more refactoring to do [3], but really keep this in mind for new code. Finkle [1] http://developer.android.com/reference/android/content/SharedPreferences.Editor.html#apply%28%29 [2] https://bugzilla.mozilla.org/show_bug.cgi?id=1061430 [3] http://mxr.mozilla.org/mozilla-central/search?string=commit%28%29&find=mobile/android/base/
_______________________________________________ mobile-firefox-dev mailing list [email protected] https://mail.mozilla.org/listinfo/mobile-firefox-dev

