Alex Rivera | Logout

SQLite database on SD card

Asked 2011-01-26T15:16:03.357
14

I'm looking to create a sqlite database on the sd card (don't want to use up the user's internal storage). I'm familiar with the OpenHelper pattern:

public DatabaseFoo(Context context) {
    OpenHelper openHelper = new OpenHelper(context);
    mDb = openHelper.getWritableDatabase();
}

private static class OpenHelper extends SQLiteOpenHelper {
    public OpenHelper(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }

    ...

so if we want to create on the sd card, I think instead we have to use:

public static SQLiteDatabase openOrCreateDatabase (String path, 
      SQLiteDatabase.CursorFactory factory);

But what is the "factory" argument supposed to be, what factory should be used?

Also a bit worried about what happens if the user removes the SD card while my app is in use..

Thanks

Edit
Report

1 Answer

2

Then make your own flat database - most people have very little internal memory, and its annoying that they eat it up with huge database.

And as for the 'what if they remove the SD' scenario - if the user removes the card obviously its not going to work! Clearly. Just check you didn't get an error when trying to interact with the base, and if you did, just tell you user - problem solved.

answered 2011-02-09T16:38:54.010

Your Answer