我需要執行一大批操作。爲了避免阻塞,我需要在執行批處理時多次執行數據庫事務。我已閱讀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