网上的文章不要全信哦,也不要乱写,误人子弟
1.我看网上很多文章说SharedPreferances中存储的数据在不同包的Activity中无法读取。他指的是Context.MODE_PRIVATE这种模式下。
但是我测试了一下,在不同包的Activity中是可以读取SharedPreferances中的数据的。(Context.MODE_PRIVATE模式下 )
而且在官方的API文章中明确指出
Context类
public static final 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).
See Also
MODE_WORLD_READABLEMODE_WORLD_WRITEABLE
public static final int MODE_WORLD_READABLE
File creation mode: allow all other applications to have read access to the created file.
See Also
MODE_PRIVATEMODE_WORLD_WRITEABLE
public static final int MODE_WORLD_WRITEABLE
File creation mode: allow all other applications to have write access to the created file.
See Also
MODE_PRIVATEMODE_WORLD_READABLE
本文澄清了关于Android中SharedPreferances的一些误解,实测显示即使在不同包的Activity间及不同应用中也可读取其数据。此外,还介绍了SharedPreferances的不同模式及其本质。

被折叠的 条评论
为什么被折叠?



