在我的應用程序中,我使用xml閱讀器從網站下載數據。之後,我與他們建立一個SQLite數據庫。所有的工作都很好,但我擔心下載過程中會發生什麼(連接中斷),數據庫不完整。從互聯網下載數據 - 注意什麼?
有沒有人有類似的條件清單,我需要做什麼爲save
下載? (例如:在下載開始前檢查連接)
在我的應用程序中,我使用xml閱讀器從網站下載數據。之後,我與他們建立一個SQLite數據庫。所有的工作都很好,但我擔心下載過程中會發生什麼(連接中斷),數據庫不完整。從互聯網下載數據 - 注意什麼?
有沒有人有類似的條件清單,我需要做什麼爲save
下載? (例如:在下載開始前檢查連接)
:
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();
}
您可以在填寫所有數據庫後設置變量。
當您繼續使用該數據庫時,如果該變量已設置或沒有設置,Ans會檢查該變量嗎?
如果其沒有設置不是Data is not completed download Please download again.
OR
再次要求下載爲你提示,當連接被中斷檢查變量你的自我,如果中斷之前,它的設定意味着下載的,否則所有的數據是不。解析XML並插入到你會做下面的代碼DB時
哇,很容易和偉大的回滾:)謝謝! – bluerob 2013-03-05 12:52:45