开发者

Android: Possible to have multiple distinct Shared Preferences per app?

开发者 https://www.devze.com 2023-01-17 22:02 出处:网络
Is it possible to have multipl开发者_开发知识库e Shared Preferences per app? If you create a PreferenceActivity, the values by default are persisted to /data/data/[PACKAGE_NAME]/shared_prefs/[PACKAGE_

Is it possible to have multipl开发者_开发知识库e Shared Preferences per app? If you create a PreferenceActivity, the values by default are persisted to /data/data/[PACKAGE_NAME]/shared_prefs/[PACKAGE_NAME]_ preferences.xml

Is there a way to have multiple such files and which one to use for a given PreferenceActivity?


Sure:

If you use PreferenceManager.getDefaultSharedPreferences(context); it will create the file you mention.

If you use context.getSharedPreferences("OtherPrefs", Context.MODE_PRIVATE); it will create a file (and SharedPreferences object) in /data/data/[PACKAGE_NAME]/shared_prefs/OtherPrefs.xml.

0

精彩评论

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