3

How can i store an array list of hashmap in shared preferences android?Any help would be appreciated.

Kirthiga
  • 271
  • 2
  • 4
  • 13

3 Answers3

4

After API 11, Shared Preferences accepts sets such as ArrayLists with HashMaps embedded in them.
Please go through this link for a thorough walk-through about saving ArrayLists to Shared Preferences:
Save ArrayList to SharedPreferences
It will solve your problem.

P.S: The sole purpose of Shared Preferences is to save the values that are less frequently accessed and that are not too Large (like the settings of Application). Therefore, if you have Data Sets that are large in sizes and are not related to to the Application's Settings, then you should go for a proper SQLite DB.

EDIT:
Other Options available for storing the Data in ArrayList is to use a proper SQLite Database.
Here is the link that contains code and information related to Storing and Retrieving ArrayLists from SQLite Database.
I hope this solves your problem.

Community
  • 1
  • 1
Salman Khakwani
  • 6,684
  • 7
  • 33
  • 58
  • Thanks for your response.Can u please tel me is there any other storage option to come out from this issue than shared preferences. – Kirthiga Aug 20 '13 at 06:17
0

What i usually do is convert the Map to a json-string and save that. Easy enough to change back to a hashmap. Works like a charm.

Check out the answer from KayKay in this thread for some example code.

Community
  • 1
  • 1
pumpkee
  • 3,357
  • 3
  • 27
  • 34
0

In order to store Object type into the SharedPrefrence.

You can refer to below post having similar issue.

Download gson-1.7.1.jar from this link: GsonLibJar

How to store class object in android sharedPreference?

Community
  • 1
  • 1
Amit Gupta
  • 8,914
  • 1
  • 25
  • 33