Key content provider docs

satya - 1/3/2015, 9:36:53 AM

content provider basics

content provider basics

satya - 1/3/2015, 9:38:07 AM

Main guide to content providers

Main guide to content providers

satya - 1/3/2015, 9:43:40 AM

Here is how batch operations are explained

Here is how batch operations are explained

satya - 1/3/2015, 9:59:47 AM

How does batch operations in a content provider work?

Each content provider update operation is encapsulated in an object called "ContentProviderOperation" along with the URI and all

You make a list of those

You tell the Content Resolver to apply the batch one time

Transactions are applied at the end of all operations

If an operation says that transaction can be applied at that point, then it will be dealt as the end of a unit of operation. this allows you to sub-batch your long updates of many rows

You can also say in an operation one of the columns to be updated needs to use the key returned by an indexed previous operation

thats it

satya - 1/3/2015, 10:00:15 AM

So in summary


Batch them
Yield when needed
use an id from a previous operation

satya - 1/3/2015, 10:08:16 AM

An example


//A list of operations
ArrayList<ContentProviderOperation> ops =  new ArrayList<ContentProviderOperation>();

//Get a builder
ContentProviderOperation.Builder op =
            ContentProviderOperation.newInsert(a content URI);
op.withValue(key, value);
//...more of these
ContentProviderOperation op1 = op.build();
ops.add(op1);

//Do more of these
op = ContentProviderOperation.newInsert(a content URI);
op.withValue(key, value);
//...more of these
//Take the key coming out of op1 and add it as the value 
op.withValueBackOperation(mykey, 0);
op.withYieldAllowed(true); //it is ok to commit

ContentProviderOperation op2 = op.build();
ops.add(op2);

contentResolver.apply(ops);

satya - 1/3/2015, 10:17:57 AM

Key classes and methods


ContentProviderOperation
ContentProviderOperation.Build
   withValue
   withValueBackReference
   withYieldAllowed
   build
contentResolver.apply()

satya - 1/3/2015, 10:19:54 AM

Read this documentation on optimistic locking

Read this documentation on optimistic locking

satya - 1/3/2015, 10:35:36 AM

Syncadapters are documented here

Syncadapters are documented here

satya - 1/3/2015, 10:36:12 AM

Reusing the UI of the contacts application is documented here

Reusing the UI of the contacts application is documented here