jibysthomas jibysthomas - 5 months ago 61
Android Question

Saving a hash map into Shared Preferences

How I can save a Hash Map into the Shared Preferences in Android?

Answer

I would not recommend writing complex objects into SharedPreference. Instead I would use ObjectOutputStream to write it to the internal memory.

File file = new File(getDir("data", MODE_PRIVATE), "map");    
ObjectOutputStream outputStream = new ObjectOutputStream(new FileOutputStream(file));
outputStream.writeObject(map);
outputStream.flush();
outputStream.close();
Comments