What Is The Best Strategy To Recover From An Error - Neglecting The Record Where Error Occurs
Solution 1:
It seems to be a Samsung specific bug. It has been reported to
- AOSP issue tracker
- at Samsung developer forum here and here
So far there does not seem to be a solution except updating your Android version (if I got that right).
Solution 2:
I would suggest to change the dbHelper.insert to be done inside a transaction this may walk-around the issue.
Although your code works is really slow and memory intensive so it may lead straight to an existing bug or occur only in "stressed" devices.
When you insert data to SQLite this way
privatevoidexecQuery(String tableName,ContentValues val)
{
sqliteDb = instance.getWritableDatabase();
sqliteDb.insert(tableName, null, val);
returntrue;
}
the android method .insert performs a lot of safe checks and then insert them. This procedure I guess allocates a lot of memory and as I measured before takes a lot more execution time than the creation of transaction and inserting data on that.
String sql = "INSERT INTO table (col1, col2) VALUES (?, ?)";
db.beginTransaction();
SQLiteStatement stmt = db.compileStatement(sql);
for (int i = 0; i < values.size(); i++) {
stmt.bindString(1, values.get(i).col1);
stmt.bindString(2, values.get(i).col2);
stmt.execute();
stmt.clearBindings();
}
db.setTransactionSuccessful();
db.endTransaction();
Note that transaction should start before first insert and end after last insert not a transaction for each insert.
More about transactions at SO here.
I know that my answer may look too irrelevant to the question but I am quite positive that the error would be avoided that way and also the performance will be much improved. Sometimes is better to change the whole logic instead of handling the error.
Post a Comment for "What Is The Best Strategy To Recover From An Error - Neglecting The Record Where Error Occurs"