Android 中的
SharedPreferences
是应用程序本地的,不会在不同应用程序之间共享。当我说
SharedPreferences preferences = getSharedPreferences(PREF_NAME, MODE_WORLD_READABLE);
设置此首选项 MODE_WORLD_READABLE
、MODE_WORLD_WRITABLE
或
MODE_PRIVATE
?
最佳答案
getSharedPreferences(String name, int mode)
解释here
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).
MODE_WORLD_READABLE: File creation mode: allow all other applications to have read access to the created file.
MODE_WORLD_WRITEABLE : File creation mode: allow all other applications to have write access to the created file.
更多信息 here
编辑
从 API 17 开始,MODE_WORLD_READABLE
和 MODE_WORLD_WRITEABLE
已弃用:
This constant was deprecated in API level 17.
Creating world-readable files is very dangerous, and likely to cause security holes in applications. It is strongly discouraged; instead, applications should use more formal mechanism for interactions such asContentProvider
,BroadcastReceiver
, andService
. There are no guarantees that this access mode will remain on a file, such as when it goes through a backup and restore.
关于带有 MODE_PRIVATE、MODE_WORLD_READABLE、MODE_WORLD_WRITABLE 的 Android SharedPreferences,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13153231/