android - Speeding up database writes -
i have listactivity uses cursoradapter display data. data result of web service call.
i getting response web service call, using org.json.* library parse it, , writing results app's sqlite3 database. listactivity's cursor re-queried , data shows in list.
my problem database writing excessively slow. thing can think not use cursoradapter , hold data in memory. hoping had suggestion speed things up. perhaps bulk insert of kind?
it should noted i'm using contentprovider inserting. call getcontentresolver().insert(...).
here times test retrieved in 56 rows of data on lan , displayed them:
time response: 178ms
time parse json: 16ms
time write 56 rows database: 5714ms
i'd time database writing under 1000ms amount of data.
i had problem once , found calling begintransaction() on database first followed executing insert queries. example code:
public void insertclassbatch(arraylist<class> batch) throws exception { this.getwritabledatabase().begintransaction(); (class c : batch) { this.insertclassstatement.bindstring(1, c.getclassname()); this.insertclassstatement.bindstring(2, c.getclassvalue()); this.insertclassstatement.executeinsert(); } this.getwritabledatabase().settransactionsuccessful(); this.getwritabledatabase().endtransaction(); }
this reduced inserting 100 rows (the size of batch in situation) 30s 300ms or so.
Comments
Post a Comment