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/[PACKAGE_NAME]_ preferences.xml
Is there a way to have multiple such files and which one to use for a given PreferenceActivity?
Yes you can maintain as many shared preference files for an app as you can.
there is no limit in Shared Preference.
getSharedPreferences() — Use this if you need multiple shared preference files identified by name, which you specify with the first parameter. You can call this from any Context in your app. getPreferences() — Use this from an Activity if you need to use only one shared preference file for the activity.
Android Shared Preferences Overview Android stores Shared Preferences settings as XML file in shared_prefs folder under DATA/data/{application package} directory. The DATA folder can be obtained by calling Environment.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With