Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android when to use ContentResolver applyBatch or BulkInsert

Right now for my application when I want to alter data for my ContentProvider, I just use the ContentResolver methods of insert, update, and delete. But on a couple of sample projects in the Android SDK, I notice they use applyBatch or BulkInsert. So I want to know when to use either of these methods and what are the advantages of using them over what I'm doing now.

like image 902
Hank Avatar asked Feb 20 '12 15:02

Hank


1 Answers

Content Providers can have observers, such as Cursors, which are notified each time an insert, update or delete happens. Usually this results in some work being done to update the UI. When you have multiple operations to apply at the same time, this could result in repetitive updates by the observers. In general, if you have multiple insert, update or deletes to perform, it's more efficient to do them in bulk.

That being said, the default ContentProvider.applyBatch() method simply iterates over the batch and applies them individually anyhow. The writer of the ContentProvider must override this and apply it more efficiently to take advantage of the batch operations.

like image 110
jsmith Avatar answered Dec 02 '22 22:12

jsmith