We can save the all the synchronized Objects in Android using File Connections even if the Object is a customized or user defined object.
Saving the Objects:
Open a file using the below code.
File suspend_f = new File("/data/data/com.rama.rama/cache/check.txt");
here i had saved the file in the application space in the device which will be removed when the application is un-installed. You can save it any where. but you should remember it for further fetching of the objects.
Opening an outputStream for the File object and writing the object to file as shown below.
fos = new FileOutputStream(suspend_f);
oos = new ObjectOutputStream(fos);
for(int i=0 ;i<10;i++)
oos.writeObject(new Lecture("Mahesh"+i, "sta", "end", "one", true));
We should read the objects in the same order that you write objects.
Reading the Objects:
Opening the file object just as like the above step1.
Opening InputStream of the File Object and reading the objects in the same order that we write in the file.
fis = new FileInputStream(suspend_f);The whole code can be downloaded from this link.
ois = new ObjectInputStream(fis);
String s = "";
_l = (Lecture)ois.readObject();