Yes you can maintain as many shared preference files for an app as you can.
there is no limit in Shared Preference.
Unlike commit() , which writes its preferences out to persistent storage synchronously, apply() commits its changes to the in-memory SharedPreferences immediately but starts an asynchronous commit to disk and you won't be notified of any failures.
You don't need any special manifest modificaiton to achieve that.
Assuming you have already saved preferences you can read those preferences at anytime doing something like I show bellow.
Write on Shared Preferences file:
SharedPreferences prefs = getSharedPreferences("your_file_name", MODE_PRIVATE); SharedPreferences.Editor editor = prefs.edit(); editor.putString("yourStringName", "this_is_the_saved_value"); editor.commit(); // This line is IMPORTANT. If you miss this one its not gonna work!
Read from Shared Preferences file:
SharedPreferences prefs = getSharedPreferences("your_file_name", MODE_PRIVATE); String string = prefs.getString("yourStringName", "default_value_here_if_string_is_missing");
You can use a default file to save/ read your preferences. Just replace the first line of the two code snippets above by something like: SharedPreferences prefs = getDefaultSharedPreferences(getApplicationContext());
Thats it! Check the Android Developers dedicated page to this matter, here.
Hope it was usefull. Let me know about it.
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