Implement your SQLiteOpenHelper as a singleton.
public class MyDatabaseHelper extends SQLiteOpenHelper {
private static MyDatabaseHelper instance;
public static MyDatabaseHelper getInstance(Context context){
if ( instance == null ){
instance = new MyDatabaseHelper(context);
}
return instance;
}
}
Look into SQLite Write-Ahead Logging
There are advantages and disadvantages to using WAL instead of a rollback journal. Advantages include:
- WAL is significantly faster in most scenarios.
- WAL provides more concurrency as readers do not block writers and a writer does not block readers. Reading and writing can proceed concurrently.
- Disk I/O operations tends to be more sequential using WAL.
- WAL uses many fewer fsync() operations and is thus less vulnerable to problems on systems where the fsync() system call is broken.
Source: https://www.sqlite.org/wal.html
Android (API level 11+):
The best way to enable write-ahead logging is to pass the
ENABLE_WRITE_AHEAD_LOGGING flag to openDatabase(String,
SQLiteDatabase.CursorFactory, int). This is more efficient than
calling enableWriteAheadLogging().
SQLiteDatabase db = SQLiteDatabase.openDatabase("db_filename", cursorFactory,
SQLiteDatabase.CREATE_IF_NECESSARY |
SQLiteDatabase.ENABLE_WRITE_AHEAD_LOGGING,
myDatabaseErrorHandler);
db.enableWriteAheadLogging();
Source
http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html#enableWriteAheadLogging()