Reputation: 37577
I have this class:
public class SaveState implements Serializable {
private static final long serialVersionUID = 1L;
public List<String> downloadedMagazinesIds = new ArrayList<String>();//id's de revistas descargadas
public List<String> downloadedMagazinesSummaries = new ArrayList<String>();//página sumario de cada magazine
public List<FullMagazine> downloadedMagazines = new ArrayList<FullMagazine>();//todos los magazines bajados
public Magazines ms=null; //Esta clase contiene el array de previews de revistas generado con el parser de XML
}
And I use these methods to store the class (SaveState object) in the sdcard and to read the object from the file into an object again:
public static void saveData(){
ObjectOutput out;
try {
//primero comprobamos si existe el directorio, y si no, lo creamos.
File folder = new File(Environment.getExternalStorageDirectory() + "/C/");
if(!folder.exists())
folder.mkdirs();
File outFile = new File(Environment.getExternalStorageDirectory(), "/C/appSaveState.data");
out = new ObjectOutputStream(new FileOutputStream(outFile));
out.writeObject(saveState);
out.close();
} catch (Exception e) {e.printStackTrace();}
}
public static void loadData(){
ObjectInput in;
try {
File inFile = new File(Environment.getExternalStorageDirectory(), "/C/appSaveState.data");
in = new ObjectInputStream(new FileInputStream(inFile));
saveState=(SaveState) in.readObject();
in.close();
} catch (Exception e) {e.printStackTrace();}
}
I store the object and each time my app is closed and I read the object from the sdcard each time my app is opened and it works fine. The problem comes when I created a newer version of my app (1.01). When I start the app and I try to read the file from the sdcard the file is read but all the variables of the object class are empty, and they are really not empty.
Why doesn't my code work properly? What should I do to fix it?
Upvotes: 2
Views: 1207
Reputation: 9574
I have attempted to edit your question to make it more readable and understandable. Hopefully it will help you get some good answers.
I suggest the following
Let me know what you find. It is a interesting question.
Upvotes: 1