I wanna know whether is it possible to store array of string in the SharedPreferences. In my application i want , set of names to be stored
You can store set of String using SharedPreferences
in API Level 11 and higher. See getStringSet() and putStringSet()ю
In API Level prior to 11 you can use some kind of hack. For example, if you need to store string array under key "stringArray", you can save each string from array using putString
and keys "stringArray.1", "stringArray.2", so on.
If you are looking for StringTokenizer then blog post 1 and blog post2 would be helpful
In shared preferences, you can store the data like key value pairs. What I usually do is to insert all the data then get the key list and iterate through it, set key as anything unique, be it numbers 1,2,3 etc
use
SharedPreference sp = context.getSharedPreferences("myPrefs", MODE_WORLD_READABLE); Map presetDataMap = sp.getAll();
then loop through presetDataMap,
Iterator itt = presetDataMap.keySet().iterator();
hope this helps.
It's not possible to store them as an array, but you can concatenate them, and then split them when loading, using StringTokenizer
. I can help with some code, if this will be helpful for you.