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
Asked
Active
Viewed 55 times
-4
-
@Danieboy not tried anything i want create alarms and it must show in home activity – Unniraja UnnI Jul 27 '16 at 11:04
1 Answers
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
-
-
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