问题
I am using SQLCipher it is working fine. I have one performance issue with this openDatabase
method. My code is
SQLiteDatabase database = SQLiteDatabase.openDatabase(databasePath,
databasePassword, null, SQLiteDatabase.OPEN_READWRITE);
This also working fine. But my problem is it takes 3 to 4 seconds time (I found time lagging in Logcat). Because of this the activity show slow response.
Note:
I am calling this code from onCreate
method after set setContentView(R.layout._list);
Am i doing right? Is there any other way to open database.
Is it right to call openDatabase from onCreate
?
回答1:
The performance issue you are seeing is most likely due to SQLCipher key derivation. SQLCipher's performance for opening a database is deliberately slow, using PBKDF2 to perform key derivation (i.e. thousands of SHA1 operations) to defend against brute force and dictionary attacks (you can read more about this at http://sqlcipher.net/design). This activity is deferred until the first use of the database.
回答2:
I have solve my problem. Once my application is open i've open my database and save that (static
method) open it from all the activities
. I am not sure which is the right way or not. But it solve my problem.
来源:https://stackoverflow.com/questions/25039038/opendatabase-in-sqlcipher-taking-time-android