We have a strange bug. Our App will loose it’s data (stored in SQLite) if the battery runs out but it doesn’t if we kill the application forcefully and then the battery runs out.
We’re not sure what could cause this.
EDIT 1:
WHAT DOES IT MEAN TO LOOSE THE DATA?
- When the user registers we save his username etc.
- When the app is closed, forced-closed and the user opens the app again the username is there
- When the battery runs out and the app is running in foreground. After the battery is recharged and the user opens the app again, the username is gone.
How are objects stored:
public Void perform(SQLiteDatabase db) {
final ConfigEntry entry = new ConfigEntry(property, value);
if(contains(property)) {
db.update(ConfigEntry.TABLE_NAME, databaseAdapter.convertToContentValues(entry), ConfigEntry.COLUMN_NAME + " = ?", new String[] { property });
} else {
db.insertOrThrow(ConfigEntry.TABLE_NAME, null, databaseAdapter.convertToContentValues(entry));
}
return null;
}
});
So basically db.insertOrThrow is called.
This is how we initialize the database:
public S doInTransaction(TransactionTask task) {
DatabaseHelper mDbHelper = DatabaseHelper.getInstance(mContext);
SQLiteDatabase mDb = mDbHelper.getWritableDatabase();
mDb.setLockingEnabled(true);
mDb.beginTransaction();
try {
S result = task.perform(mDb);
mDb.setTransactionSuccessful();
return result;
} finally {
mDb.endTransaction();
}
}
Thanks a lot for all the Help, we finally found the answer.
We are encrypting our database using a user password and salting the password with the MAC adddress of the device.
What happened is that sometimes when the user ran out of battery after the boot, when our app was ran and we requested for the MAC address it failed because the network card it’s still disabled or something. In that case we created a new salt which when trying to read the DB would fail.