Store object/data in internal memory

In many apps you need to store object/data in internal memory (custom Object, collection object: ArrayList, HashMap ecc.. ) in memory. In Android it’s very simple, for example if you want store a object “City”:

FileOutputStream stream = null;

/* you should declare private and final FILENAME_CITY */
stream = ctx.openFileOutput(FILENAME_CITY, Context.MODE_PRIVATE);
ObjectOutputStream dout = new ObjectOutputStream(stream);
dout.writeObject(city);

dout.flush();
stream.getFD().sync();
stream.close();

if the file (FILENAME_CITY) doesn’t exist, the system will create the file.

android-tutorial , , , , ,

1 response to Store object/data in internal memory


  1. R4 3DS

    Great, thanks for sharing

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>