Is it a good idea to store a list of String
with too many items in Sharedpreferences
? Does it hurt app performance?
I'm doing this to store:
public boolean saveArray(List<String> contacts) {
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(_context);
SharedPreferences.Editor editor = sp.edit();
editor.putInt("Status_size", contacts.size());
for (int i = 0; i < contacts.size(); i++) {
editor.remove("Status_" + i);
editor.putString("Status_" + i, contacts.get(i));
}
return editor.commit();
}
And to read:
public void loadArray(Context context) {
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
_validContactsPhones.clear();
int size = sharedPreferences.getInt("Status_size", 0);
for (int i = 0; i < size; i++) {
_validContactsPhones.add(sharedPreferences.getString("Status_" + i, null));
}
}