SQLCipher can't open database after apprestart
you might need the table ANDROID_METADATA
with (key,value)=('locale',YOUR LOCALE)
It look like you are opening the database again when your app restart.I had the same error but I solve it by creating a helper class which cache the previously opened database and only open it if it is really needed like below.
public class Helper { private static net.sqlcipher.database.SQLiteDatabase database; public static net.sqlcipher.database.SQLiteDatabase openDatabase(Context context, String databaseName, String password) { if (database == null) { database = net.sqlcipher.database.SQLiteDatabase .openOrCreateDatabase(context.getDatabasePath(context.getResources().getString(database)), password, null); } return database; }}
So when your app restart try to called openDatabase() method again.
This line looks weird to me:
databaseFile.mkdir();
mkdir()
creates a folder, hence you are passing a folder instead of a file to openOrCreateDatabase()
.
Also I think you shouldn't call openOrCreateDatabase()
in the SQLiteOpenHelper's constructor. It takes care of creating the database file automatically. Then you can get the SQLiteDatabase
object by calling for example SQLiteOpenHelper.getWritableDatabase(password)
.