-4

Im creating a alarm app that will have multiple alarm.. so i want to store the times in shared preference. if there is any solution to store integer list in shared preference

1 Answers1

1
SharedPreferences preferences = getSharedPreferences("prefs", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
editor.putInt("key", yourIntValue);
editor.apply();

Use editor.apply() to save preferences asynchronously. apply() is preferable in the most cases.

Use editor.commit() to save preferences synchronously.

Vadims Savjolovs
  • 2,618
  • 1
  • 26
  • 51
  • i want to list all alarms created ? – Unniraja UnnI Jul 27 '16 at 11:02
  • SharedPreferences are a key-value storage. By code above you are adding key - int value pair. Not key - int list pair. You have 3 options. 1. save each alarm with different key (bad idea); 2. Save them as string set using putStringSet; 3. Use database, file etc instead of sharedPreferences – Vadims Savjolovs Jul 27 '16 at 11:09