MODE_MULTI_PROCESS

来源:互联网 发布:spearman相关系数 知乎 编辑:程序博客网 时间:2024/06/06 02:35
/**
     * SharedPreference loading flag: when set, the file on disk will
     * be checked for modification even if the shared preferences
     * instance is already loaded in this process.  This behavior is
     * sometimes desired in cases where the application has multiple
     * processes, all writing to the same SharedPreferences file.
     * Generally there are better forms of communication between
     * processes, though.
     *
     * <p>This was the legacy (but undocumented) behavior in and
     * before Gingerbread (Android 2.3) and this flag is implied when
     * targetting such releases.  For applications targetting SDK
     * versions <em>greater than</em> Android 2.3, this flag must be
     * explicitly set if desired.
     *
     * @see #getSharedPreferences
     */

    public static final int MODE_MULTI_PROCESS = 0x0004;

看到settingManager在载入sharedPref时,getSharedPreferences()会使用这个标记,其实作用和C的violate有点像,

及该prefs在读入到内存以后,也有可能被其他的进程改变,那么,对与prefs的每次修改都要做出回应,适用于多进程。

这个行为在2.3以前是默认,后面要用必须显式的加上,估计是为了性能吧.


0 0
原创粉丝点击