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.

images

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

Leave a Reply

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