问题描述:

Copying .sqlite file takes too much time. Can I work with it in assets folder?

网友答案:

Copying .sqlite file takes too much time. Can I work with it in assets folder?

If you will place .db file there, for sure it will works but this is not the best choice but it depends on more things. Efficient way is to place file on SD card and only provide reading from it. This is useful if your db file has bigger size.

But also all possible approaches have advantages and disadvantages. For example placing database on sd card is not really safe but effective if db file has big size. Do you imagine case if you have db file that have for example 200 MB. Placing it into assets folder is "sick".

Also it depends also on character of application, supposed size of db, desired performance etc.

Here is basic snippet of code of you want to read from:

        db = SQLiteDatabase.openDatabase(db_path, null, SQLiteDatabase.NO_LOCALIZED_COLLATORS | SQLiteDatabase.CREATE_IF_NECESSARY);
        if (db != null && db.isOpen()) {
            return db;
        }
        return null;
相关阅读:
Top