Android operation method of SQLite database stored in assets folder

This article describes the method of Android operating SQLite database stored in assets folder. Share with you for your reference. The details are as follows:

Because the project needs its own data, it puts all the data into a SQLite database file, and then puts the file under the assets folder. At first, I planned to copy the folder under the assets folder to the SD card of the mobile phone or the storage of the mobile phone before using it. Later, considering that the efficiency of copying every time is not high, and if the modification of the database is involved, the data will be restored after copying.

Therefore, the package is written. The package only copies the folder to the / data / data / application registration / database folder of the mobile phone when using the database file for the first time, and then directly uses it from this place. And it allows you to obtain the sqlitedatabase object directly through the database name under the assets folder, which greatly facilitates your use of the database.

The package is as follows:

The use process is also very simple. The application can be initialized at the beginning, and then the manager can be obtained anywhere. The sqlitedatabase object can be obtained directly through the database file name under the assets folder, and then the operation of the database is completely up to you... Simple use examples:

It should be noted that the case of database file names is distinguished when obtaining database objects.

I hope this article will be helpful to your Android program design.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>