Database corruption can also happen when you open the same database file
multiple times simultaneously. When the database is broken SQLiteDatabase
simply re-creates the database file by default. I think that is largely
fixed in newer Android versions and you would get a DatabaseLockedException
if you try to open it multiple times.
Make sure to:
1. Only use a single SQLiteDatabase connection / SQliteOpenHelper per
2. Open / close that connection at appropriate times in your activity
If you create the connection in onCreate / onResume and close it in onStop
or onDestroy for example it is very likely that you'll end up with two open
SQLiteDatabase connection objects simultaneously because two activities are
likely to intersect in that case. You could probably get around that by
opening the connection object in onResume and closing it in onPause.
Alternatively you can keep your database connection object as a singleton
in your application object for example. Keep a reference counter there too.
Every time when your activity starts it can request the db connection and
increment the reference counter by one. When your activity is done
(onDestroy) it can decrement the counter. If the counter hits zero you can
close the db connection.