How to get all values of SharedPreferences programmatically in Android

SharedPreferences stores all values in XML file. So, if you want to iterate through all the values stored in it, you could try following code. public static List getAllValues(Context context) { Map values = getPref(context).getAll(); List prefDataList = new ArrayList(); for (Map.Entry entry : values.entrySet()) { PrefData prefData = new PrefData(); prefData.key = entry.getKey(); prefData.value = entry.getValue().toString(); prefDataList.add(prefData); } return prefDataList; } (more…)
Read More

Store Data – SharedPreferences – Android

When it comes to store data like username for a user specific application, or checking how many times the application is opened. It is not a good choice to manage a database. As mentioned in previous blog posts, Android SQLite Database - Part 1, and Android SQLite Database - Part 2, it will be time consuming. In conjunction to that, it is not going to fulfil why database is for and database transactions are costly for such one time transaction. So, it is good if you choose to save data, like in above example, in SharedPreferences. (more…)
Read More