Question

In my application I'm downloading data from a website with a xml reader. After that I build an sqlite database with them. All works fine, but I'm afraid that something in the download process can happen (connection interrupts), by which the database is not complete.

Does anyone have something like a list with conditions as to what I need to do for a save download? (for example: check connection before the download starts)

Was it helpful?

Solution

when parsing the XML and inserting into the DB you'll do the following code:

db.beginTransaction();
try {


 // here you parse and insert onto the DB.
 // if any exception is reached (the XML reader connection was dropped or whatever)
 // it will catch the exception and end the transaction without making it successful
 // and SQLite will rollback all the actions you've done here.



  db.setTransactionSuccessful();
} catch(Exception e){
  Log.e("MyTag", "Transaction fail. " +
                  e.getClass().getSimpleName() + " - " + 
                  e.getMessage());
}finally {
  db.endTransaction();
}

OTHER TIPS

You can set a variable after filling all database.

Ans check that variable when you accese that database that if that variable is set or not ?

If its not set than ask for download again as Data is not completed download Please download again.

OR

As you suggesting your self when connection is interrupting check that variable if its set before interrupting it means all data downloaded otherwise it is not.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top