Tag Archives: serialization

Android Java Serialization Using Generics

I have created a class – SerializationManager, it can serialize any objects and write them to files. It can be used to save and restore form states in Android. It is based on Java Generics. What is achieved by this is that you do not need to duplicate serialization code in every class.


Object must implement Serialized interface. Here form is an object instance of a class. It can be named as just obj.

This is how you can use it. First you declare a SerializationManager in your class and you tell it which class you are going to serialize:

Then in onCreate method you create SerializationManager instance:

Writing object to a file:

Reading objects from saved file:

A little joke for reading to the end:
java generics

Serialize an object, save it to a file and read it from a file in Android

Android interface Serializable is not sufficient to save your objects to the file, it only creates streams.

This is a complete code with error handling and handling closes of streams. Add it to your class that you want to be able to serialize and deserialize.

In my case the class name is CreateResumeForm. You should change it to your own class name.

Use it like this in your Activity: