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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With