Android SQLite database: slow insertion

前端 未结 5 1951
南方客
南方客 2020-11-22 07:26

I need to parse a fairly large XML file (varying between about a hundred kilobytes and several hundred kilobytes), which I\'m doing using Xml#parse(String, ContentHand

5条回答
  •  北荒
    北荒 (楼主)
    2020-11-22 07:28

    You should do batch inserts.

    Pseudocode:

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

    That increased the speed of inserts in my apps extremely.

    Update:
    @Yuku provided a very interesting blog post: Android using inserthelper for faster insertions into sqlite database

提交回复
热议问题