apply Independent Operations Batch on Context - Android android.content

Android examples for android.content:ContentProvider

Description

apply Independent Operations Batch on Context

Demo Code


//package com.book2s;
import java.util.ArrayList;
import android.content.ContentProvider;
import android.content.ContentProviderOperation;
import android.content.ContentProviderResult;

import android.content.Context;
import android.content.OperationApplicationException;

public class Main {
    public static ContentProviderResult[] applyIndependentOperationsBatch(
            Context context, String contentAuthority,
            ArrayList<ContentProviderOperation> operations) {
        try {/*  w  w  w  .  j  ava2 s . c  o m*/
            final int numOperations = operations.size();
            final ContentProviderResult[] results = new ContentProviderResult[numOperations];
            ContentProvider contentProvider = context.getContentResolver()
                    .acquireContentProviderClient(contentAuthority)
                    .getLocalContentProvider();
            for (int i = 0; i < numOperations; ++i) {
                results[i] = operations.get(i).apply(contentProvider,
                        results, i);
            }
            return results;
        } catch (OperationApplicationException e) {
            throw new RuntimeException("Problem applying batch operation",
                    e);
        }
    }
}

Related Tutorials