I’m using a TreeMap because it’s the most efficient data structure for storing the information I need. I have to be able to persist the TreeMap for future use, so is there a way for me to store it in a SharedPreferences object, maybe serialize it before doing so?
I’m aware of this method here, but using ObjectSerializer from the Apache Pig project makes Eclipse crash. When I run the app, the status bar at the bottom never goes past the message “Launching [app name] 100%”, until it throws the following error message:
Unable to execute dex: Java heap space
Unhandled event loop execution
Is there anything I can do to store the TreeMap inside the shared prefs?
If you want to serialize/deserialize, you can go for serializing TreeMap into JSON format as a string object and then store it whereever you want to store it. Later you would be able to deserialize it from JSON format.
You can use famous jackson library for it as jackson library is the industry standard and is free. See at http://wiki.fasterxml.com/JacksonHome.
Edit: JSON format also ensures that you can read the persisted data in other programs as it would be very much readable. Not sure if Jackson JSON library works on android. If so find out some other library for JSON in android.