Android ContentProvider和ContentProviderOperation.newUpdate()

Android ContentProvider和ContentProviderOperation.newUpdate(),android,android-contentprovider,Android,Android Contentprovider,我试图在自定义contentprovider上使用重写的applyBatch()方法。我知道它通过了ContentProviderOperations的ArrayList。在我的例子中,它们都是更新ContentProviderOperations。在我的提供程序中,我想更新一个简单数组中的数据(现在是我的备用数据库),该数组最初插入到ContentProviderOperation.Builder中 到目前为止,重要的代码位包括: 其中,我使用通道阵列中的数据构建ContentProvider

我试图在自定义contentprovider上使用重写的applyBatch()方法。我知道它通过了ContentProviderOperations的ArrayList。在我的例子中,它们都是更新ContentProviderOperations。在我的提供程序中,我想更新一个简单数组中的数据(现在是我的备用数据库),该数组最初插入到ContentProviderOperation.Builder中

到目前为止,重要的代码位包括:

其中,我使用通道阵列中的数据构建ContentProviderOperations:

public void setNumValues(Uri mindex, int[] channels)
        {//setting type to 0 first for everything
            //first is RPM, then Speed
            ContentValues[] values = new ContentValues[channels.length];        
            ArrayList<ContentProviderOperation> operations = new ArrayList<ContentProviderOperation>();

        for (int i = 0; i< channels.length-1; i++){
            values[i].put(NumberProvider.numColumnNames[NumberProvider.VALUE], channels[i]);
            values[i].put(NumberProvider.numColumnNames[NumberProvider.TYPE], 0);

        operations.add(ContentProviderOperation.newUpdate(NumberProvider.NUM_PROVIDER_MODEL_URI).withValues(values[i]).build());
        }
        //values.put(NumberProvider.numColumnNames[NumberProvider.VALUE], value);   
        //mContext.getContentResolver().update(mindex, values, null,null);
        try {
            mContext.getContentResolver().applyBatch(NumberProvider.NUM_AUTHORITY,operations);
        } catch (RemoteException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (OperationApplicationException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
public void setnumvalue(Uri mindex,int[]通道)
{//首先将所有内容的类型设置为0
//首先是转速,然后是速度
ContentValues[]values=新的ContentValues[channels.length];
ArrayList操作=新建ArrayList();
对于(int i=0;i
然后,我的提供程序中被重写的方法:

@Override
    public int update(Uri uri, ContentValues values, String selection,
            String[] selectionArgs) {
        int tableindex = (int) (ContentUris.parseId(uri));

    if ((tableindex > 0) && (tableindex <= numProviderDataList.size())) {
        numProviderDataType Data = numProviderDataList.get(tableindex - 1);

        Data.value = values.getAsInteger(numColumnNames[VALUE]);


        // Log.e("Provider1", Float.toString(Data.mValue1));
        // Log.e("Provider2", Float.toString(Data.mValue2));
    }

    getContext().getContentResolver().notifyChange(uri, null);

    return 1;
}

@Override
public ContentProviderResult[] applyBatch(
        ArrayList<ContentProviderOperation> ops)
        throws OperationApplicationException {
    // TODO Auto-generated method stub
    ContentProviderResult[] result;
    try{
    result = super.applyBatch(ops); //Does this call my provider's update() method?

    } catch(OperationApplicationException e){
        throw e;
    }
    //let observer know there's been a change at the URI
    getContext().getContentResolver().notifyChange(NUM_PROVIDER_MODEL_URI, null);
    return result;
@覆盖
公共int更新(Uri、ContentValues、字符串选择、,
字符串[]selectionArgs){
inttableindex=(int)(ContentUris.parseId(uri));

如果((tableindex>0)和&(tableindex,
applyBatch
的默认实现将迭代
ContentProviderOperation
数组,并对每个数组调用apply,这反过来将调用提供者的
插入
更新
删除
方法

因此,是的,它将在默认情况下调用重写的方法


似乎无法从
ContentProviderOperation
提取数据,只能调用apply。重写
applyBatch
只能用于筛选或排序操作。除此之外,您只需依靠
插入
更新
删除
实现即可
applyBatch
的故障实现将迭代
ContentProviderOperation
数组,并对每个数组调用apply,这反过来将调用提供者的
insert
update
delete
方法

因此,是的,它将在默认情况下调用重写的方法

似乎无法从
ContentProviderOperation
提取数据,只能调用apply。重写
applyBatch
只能用于筛选或排序操作。除此之外,您只需依靠
插入
更新
删除
实现即可