Transfer from http://hi.baidu.com/hfutonline/blog/item/62b1e4de8bdf4b2e5882dd28.html
Recently when doing Android project encountered a problem, the application initialization needs to batch to SQLite to insert a large number of numbers, causing the application to start too slow.
Android using SQLite database, SQLite is a relatively lightweight database, after Google found that the problem of sqlite transaction processing, when SQLite inserts the data by default a statement is a transaction, how many times the number of data on the disk operation. My application initial 5,000 records that is to read and write disk operations 5,000 times.
Workaround:
Add a transaction, insert 5,000 as a transaction
Database.begintransaction (); Set up a start transaction manually
Data insertion Operation cycle
Database.settransactionsuccessful (); Set transaction success, do not set automatically rollback does not commit
Database.endtransaction (); Processing complete
To "pour out" the database:
Sqlite3 film.db ". Dump" > Output.sql
Using the output data, create an identical database (plus the above directive, which is the standard SQL database
Backed up):
Sqlite3 Film.db < Output.sql
When inserting a large amount of data, you may need to call this command first:
Begin
After inserting the data, remember to call this command, the data will be written into the database:
Commit
Android SQLite BULK INSERT data speed Solutions