In my app I am using XML to store images drawn by user on canvas. After each figure is drawn I write the points to an xml file and store it in disk. The xml is fairly large. So it take a while before the write is finished. This is the code I am using for that.
private void writeToXml( final Book book)
{
Thread t = new Thread() {
@Override
public void run() {
try {
Serializer serializer = new Persister();
File result = new File(android.os.Environment.getExternalStorageDirectory() + "/MyBooks/Book.xml");
try {
serializer.write(book, result);
} catch (Exception e1) {
e1.printStackTrace();
}
} finally {
//updateBook();
}
}
};
t.start();
}
The issue for me is if the user quits the app before the write is finished the XML file will be corrupted. How can I do this better. How can I ensure that even the app is closed the file will be properly written?
Thanks