The Android database is written through a transaction at every write, so the consequence is that the speed of writing is super slow, one is near 100ms, then thousands of, no more than two minutes.
To speed up, you have to put all the INSERT statements in one transaction, so the speed is greatly increased.
Db.begintransaction ();//Start Transaction try { String s = null; for (int i = 0;i< array.size (); i++) { s = array.get (i); Contentvalues contentvalues = new Contentvalues (); Contentvalues.put ("P_url", s); Contentvalues.put ("P_class", "null"); Da.getwritabledatabase (). Insert ("P_classification", null,contentvalues); } Db.settransactionsuccessful ();//SET transaction does not roll back, if not set then it will be the same as not set the transaction speed }finally { db.endtransaction ();//End Transaction Event } Db.close ();
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Accelerated write to the Android SQLite database