The goal: refresh database from XML data
The process:
Pretty standard stuff as far as db operations. The problem is that CRUD operations are not done within ContentProvider
but rather using ContentResolver
so the insert for example looks like resolver.insert(CONTENT_URI, contentValues)
. The ContentResolver API doesn't seem to have anything pertained to transaction and I cannot use bulkInsert
since I'm inserting in 2 tables intermittently (plus I want to have delete
inside the transaction as well).
I was thinking of registering my customized ContentProvider
as listener by using registerContentObserver
but since ContentResolver#acquireProvider
methods are hidden how do I obtain the right reference?
Am I out of luck?
I've seen that in the source code of Google I/O application, they override ContentProvider
's applyBatch()
method and use transactions inside of it. So, you create a batch of ContentProviderOperation
s and then call getContentResolver().applyBatch(uri_authority, batch)
.
I'm planning to use this approach to see how it works. I'm curious if anyone else has tried it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With