I have a version of the Application in production, where it is allowed to mark a message as a favorite, but this totally random error happens causing database corruption and resulting in application failure.
I know that I do a little risky operations according to the SQLite staff themselves.
The procedure is as follows:
- start the upgrade procedure
- copies the user database to a temporary file
- copies the new database to the device
- attaches the old base to the new
- copies required data (such as favorite messages)
- Detach temporary base
- exclude temporary base
This procedure is done on thousands of devices, mostly everything is fine, but it has started to become a frequent case.
Does anyone know how to minimize this?
ERROR:
java.lang.RuntimeException: Unable to start activity ComponentInfo{br.com.redrails.torpedos/br.com.redrails.torpedos.MainActivity}: android.database.sqlite.SQLiteDatabaseCorruptException: error code 11: database disk image is malformed
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1970)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1995)
at android.app.ActivityThread.access$600(ActivityThread.java:128)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1161)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4514)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.database.sqlite.SQLiteDatabaseCorruptException: error code 11: database disk image is malformed
at android.database.sqlite.SQLiteStatement.native_1x1_long(Native Method)
at android.database.sqlite.SQLiteStatement.simpleQueryForLong(SQLiteStatement.java:138)
at android.database.DatabaseUtils.longForQuery(DatabaseUtils.java:791)
at android.database.DatabaseUtils.longForQuery(DatabaseUtils.java:779)
at br.com.redrails.torpedos.MensagemDAO.reloadQuantidadeTotal(MensagemDAO.java:144)
at br.com.redrails.torpedos.MensagemDAO.getQuantidadeTotal(MensagemDAO.java:149)
at br.com.redrails.torpedos.MainActivity.onCreate(MainActivity.java:85)
at android.app.Activity.performCreate(Activity.java:4465)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1053)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1934)
... 11 more