我需要执行一大批操作。为了避免阻塞,我需要在执行批处理时多次执行数据库事务。我已阅读article约ContentProviderOperation.withYieldAllowed()
。这完全适合我的情况。ContentProviderOperation.withYieldAllowed()它甚至可以工作吗?
我不明白的是:如果android应该提交交易,如果ContentProvider.applyBatch()
方法不处理交易?当文档(API 23)声明获取交易行为时,您的ContentProvider必须重写该方法。
/**
* 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(
所以这意味着我要检查,如果操作允许屈服,并承诺我applyBatch()
里面执行自己的交易?这没有多大意义,我错过了什么?
那么,它是否会导致ContentProvider提交任何事务,因为它应该或不? – Gus