I need to execute a big batch of operations. To avoid blocking I need to begin and commit database transactions several times while executing this batch. I've read this article about ContentProviderOperation.withYieldAllowed()
. This would fit perfectly to my case.
What I don't understand is: how android is supposed to commit the transactions if the ContentProvider.applyBatch()
method do not handle transactions ?. As the documentation (API 23) state to get the transactional behaviour your ContentProvider must override the method.
/**
* Override this to handle requests to perform a batch of operations, or the
* default implementation will iterate over the operations and call
* {@link ContentProviderOperation#apply} on each of them.
* If all calls to {@link ContentProviderOperation#apply} succeed
* then a {@link ContentProviderResult} array with as many
* elements as there were operations will be returned. If any of the calls
* fail, it is up to the implementation how many of the others take effect.
* This method can be called from multiple threads, as described in
* <a href="{@docRoot}guide/topics/fundamentals/processes-and-threads.html#Threads">Processes
* and Threads</a>.
*
* @param operations the operations to apply
* @return the results of the applications
* @throws OperationApplicationException thrown if any operation fails.
* @see ContentProviderOperation#apply
*/
public @NonNull ContentProviderResult[] applyBatch(
So this mean I have to check if the operation allows yielding and commit the transaction myself inside my applyBatch()
implementation ? This don't make much sense, what am I missing ?