How android loads fixed content Databases

Source: Internet
Author: User

We often need to use databases with prepared content, such as dictionaries. This requires loading existing database files and storing them in assets or raw, copy to the internal space of the program when the program is running:/data/package/my_app/databases. For details, refer to here.

However, this has a disadvantage. When the file is large, it will take a long time, and the user will inevitably be a little worried.
We can use HACK to save the copy process as follows:
1. Place the database file (such as MYDB. db) in PROJECT/libs/armeabi/and change it to libMYDB. db. so (note that "lib" must be added before ").
2. Open it in this way:
[Java]
DATABASE_PATH = "/data/" + packageName + "/lib /";

SQLiteDatabase db = SQLiteDatabase. openDatabase (DATABASE_PATH + libMYDB. db. so, null, SQLiteDatabase. OPEN_READONLY | SQLiteDatabase. NO_LOCALIZED_COLLATORS );

In this way, the database can be used after the program is installed. The principle is to disguise the database file as a lib library file, during installation, the program will automatically copy to/data/package/lib/, saving our own copy process.
Currently, I have tested the read operation and the write operation is still to be tested.
(Full text)


From herbert's knowledge base

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.