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)