AsyncQueryHandler
doesn't support bulkInsert
probably because this method makes no guarantees about the atomicity of the insertions. What does this mean? Well, if startInsert
fails for some reason, then there is no insertions done. This means you can have either No insertions made, or One insertion made. There are only 2 options. Atomicity is maintained, i.e, if failed the underlying data source remain the same as before.
If bulkInsert
of 10 items should fail in the middle for some reason, there can be many options: 3 items are inserted or 5 items are inserted. Thus there is no atomicity. This happens when the ContentProvider
doesn't override bulkInsert
and ends up using the implicit insert
multiple times. So after each item is inserted, the transaction is considered successful and the commit is made. This means for 10 items, 10 transactions occur, and if any one fails in between, there is no rolling back to the previous state of the data source. The atomicity of the operation is lost.
But this is bad. What if you own the ContentProvider
and you have overridden bulkInsert
and ensured atomicity is maintained. Then you should be able to use AsyncQueryHandler
to perform bulkInsert
. https://github.com/Madrapps/AsyncQuery library does exactly that. It's the same AsyncQueryHandler
of Android, but supports bulkInsert
.
Just make sure you use your own ContentProvider
that could handle bulkInsert
if you are concerned about atomicity.