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

后端 未结 1 1998
南方客
南方客 2020-12-15 22:18

Is it possible to have multiple Shared Preferences per app? If you create a PreferenceActivity, the values by default are persisted to /data/data/[PACKAGE_NAME]/shared_prefs

相关标签:
1条回答
  • 2020-12-15 22:33

    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 讨论(0)
提交回复
热议问题