SharedPreferences使用经验

SharedPreferences使用经验


int

MODE_APPEND

File creation mode: for use with openFileOutput(String, int), if the file already exists then write data to the end of the existing file instead of erasing it.

int

MODE_MULTI_PROCESS

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.

int

MODE_PRIVATE

File creation mode: the default mode, where the created file can only be accessed by the calling application (or all applications sharing the same user ID).

int

MODE_WORLD_READABLE

File creation mode: allow all other applications to have read access to the created file.

int

MODE_WORLD_WRITEABLE

File creation mode: allow all other applications to have write access to the created file.

1、对于SharedPreferences来说,使用MODE_APPEND是没有意义的,这个标志表示文件可以追加,即可以继续向一个txt里面写东西,而MODE_PRIVATE 活着其他  会覆盖文件

2、当使用这几种权限时,其他程序访问数据时启动本程序修改文件数据,其他程序得到的还是缓存数据得不到最新的数据,其他程序要想得到最新数据,本程序在写文件时必须使用MODE_MULTI_PROCESS权限。
如果不通过创建Context访问其他应用的preference,可以以读取xml文件方式直接访问其他应用preference对应的xml文件

你可能感兴趣的:(SharedPreferences使用经验)