【android】批量插入數據提高速度解決

項目中遇到處理批量插入數據的功能。後期提高了插入數據效果,用事務的方式。

在ContentProvider 中重寫方法:

    @Override
    public ContentProviderResult[] applyBatch(ArrayList<ContentProviderOperation>operations)
                throws OperationApplicationException{
              SQLiteDatabase db = mOpenHelper.getWritableDatabase();
              db.beginTransaction();//開始事務
              try{
            	  ContentProviderResult[]results = super.applyBatch(operations);
                  db.setTransactionSuccessful();//設置事務標記爲successful
                  return results;
              }finally {
            	  db.endTransaction();//結束事務
              }
    }


利用ContentProviderOperation ,ContentResolver的applyBatch即可。

感謝同事牛人指點。O(∩_∩)O~

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章