您好我正在使用应用启动时的服务器更新我的数据库并在共享首选项中维护服务器(db)版本。当应用程序从最近关闭时,该过程突然停止,没有任何回调。如果应用程序在setTransactionSuccessful和editor.putInt之间终止,任何人都可以建议一个可能的解决方案来维护更新的正确版本。
// create a http url connection and get the inputstream
InputStream is = connection.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(is));
String readLine = null;
db.beginTransaction();
while ((readLine = br.readLine()) != null) {
// read a line and insert the record into table
db.execSQL(readLine);
}
db.setTransactionSuccessful();
db.endTransaction();
// save the latest db version from the server in shared preference.
// if app closed from recents need to maintain the last version updated from server
editor.putInt("db_version", 6).commit();