SQLite database on SD card

I haven’t tried to do what you describe there, but presumably it could be done and might work — with a few caveats. First, the external storage (SD card) is not secure, so any other application, or the user, could read/write to it. Second, as you noted, when it’s unmounted the DB goes away.

Because of these disadvantages, you would probably be better off to try to use an internal storage database (the default), that is small and possibly includes pointers to external data (like images or files) — that themselves can be on the external storage (and that have placeholders, or other handling, when the external storage is not available).

Still, if you want to try it, you might be better off override the getDatabasePath method of Context, such as with your own Application object, and then pass that into a regular SQLiteOpenHelper. Then you wouldn’t have to worry about the cursor factory (which is optional, as the source confirms — so just pass null if instead you want to go that route).

Leave a Comment