How to improve performance for SQLite database for android

后端 未结 1 1874
轮回少年
轮回少年 2021-02-04 12:15

There are few questions related to this topic on stackoverflow, But I didn\'t get the proper answer. I have some doubts on performance of flat files, Is it better to use flat fi

相关标签:
1条回答
  • 2021-02-04 12:21

    I believe you are inserting 1000 or 10000 using a loop. Use TRANSACTIONS , it will dramatically reduce the write time. I already encountered such an issue and it reduced the write time in my case from around 30 seconds to about less than 1 second.

    Take a look at this.

    Basically, what you should do is :

    db.beginTransaction();
    try{
        for(int i = 0 ; i < LENGTH ; i++ ) {
            // execute SQL
        }
        db.setTransactionSuccessful(); // marks a commit
        }
    finally{
        db.endTransaction();
    }
    
    0 讨论(0)
提交回复
热议问题