As the database in my app grows, it is going to require more and more of the internal phone space. There isn't any sensitive/private data in the DB, so I'm interested in moving it to the SD card.
I'm using SQLiteOpenHelper to assist with the database work. It's my understanding that you can't use this for DB-access on the SD card as you can't define the DB path. However, there are some (very poor) examples on the Internet that suggest you can override this limitation. However I've never gotten one of those code samples to compile.
Is it possible? And if so--HOW! Please note that Froyo's "apps on SD card" feature won't work as it doesn't move internal files.
I found I could use a full path in Android 2.2, but in 2.1 the Context.openOrCreateDatabase() method threw an exception. To work around this I wrapped that method to call SQLiteDatabase.openOrCreateDatabase() directly. Here is the constructor for my extended SQLOpenHelper
For me this works, and WorkoutDBOpenHelper extends SQLiteOpenHelper and its constructor simply calls super for SQLiteOpenHelper.
Please note that SQLiteopenHelper creates the database on the memory card too. However, on app uninstall, the DB will not be deleted from the sdcard.
This is not the answer for how to move an existing internal DB to SDCard, but this way you can choose one option at the creation time. I am working on moving the already existing database from app's "data" directory to sdcard, but there is no direct way. Will update once I figure out something.
This will be ok. I thought
Just use:
where DB_FULL_PATH can be a path to your sdcard, like /sdcard/mydatabase.db
Edit:
This is what I call in my application to access the database....
... and this is the db helper class I'm using, which in fact extends SQLiteOpenHelper, so you will still have everything you want from this class.