danybarco
danybarco

Reputation: 328

Android sqlite execute multiple queries on json read

I'm reading a web service that returns a JSON, parse and write into a SQLite Database in Android. The process is very slow because I have to do each insertion separately.

I do this process in background

Is there a way to improve this process?

Thank you!!!

Upvotes: 0

Views: 549

Answers (1)

JuanMa Cuevas
JuanMa Cuevas

Reputation: 1182

You should do batch inserts.

Pseudocode:

db.beginTransaction();
for (entry : listOfEntries) {
    db.insert(entry);
}

db.setTransactionSuccessful();
db.endTransaction();

That increased the speed of inserts extremely.

If it doesn't work check out this post about faster insertions

Upvotes: 1

Related Questions