Improve the efficiency of SQLite large-capacity data storage on the Android platform

Source: Internet
Author: User

During the development process, tens of thousands of pieces of data are parsed in XML, and it is found that it takes a lot of time to insert data in SQLite because transactions are not used. By default, transactions are inserted every time.

In this case, if pieces of data are inserted, transactions will be started, which is very time-consuming. Therefore, we can manually start and close the transaction.

Add the insert method to the subclass that inherits sqliteopenhelper.

[HTML]
/**
* Databasename is the table name.
* Valuesarr is the data to be inserted.
*/
Public void insertall (string databasename,
Arraylist <contentvalues> valuesarr ){
Sqlitedatabase DB = getwritabledatabase ();
DB. begintransaction ();
For (contentvalues VAL: valuesarr ){
DB. insert (databasename, null, Val );
}
 
DB. settransactionsuccessful ();
DB. endtransaction ();
DB. Close ();
}
In this way, the data insertion time will be significantly improved. (The time varies with the performance of the device)

Related Article

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.