开发者

Can Shared Preferences be private?

From the name alone, I am guessing that Shared Preferences are... shared among apps? That is, even if my app defines and creates them, any app on android can access them. Is this correct?

(If this isn't correct, then why does t开发者_开发问答he Data Storage Dev Guide emphasize Internal Storage as "Store private data"?)

If this is correct, can I modify this default behavior so that a preference is only visible from the app in which I define and create it?

If so, how do I do that?


SharedPreferences are private by default. They are shared among the components of your app.


If i'm correct you can make store it as private by calling

getSharedPreferences(yourfile, MODE_PRIVATE);


public static final int MODE_PRIVATE 

Since: API Level 1 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_READABLE
MODE_WORLD_WRITEABLE 
Constant Value: 0 (0x00000000) 


The getSharedPreferences in the Context class takes two arguments, String name and int mode. Mode determines if the shared preferences are private or not. Context.getSharedPreferences

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜