I need to make insert of few rows in one transaction. Can I do it with ContentProvider?
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
相关文章
- android开发 怎么把图片放入drawable的文件夹下
- android上如何获取/storage/emulated/下的文件列表
- androidStudio有个箭头不认识
- SQLite不能创建表
- Windows - Android SDK manager not listing any plat
- Animate Recycler View grid when number of columns
- Why is the app closing suddenly without showing an
- Android OverlayItem.setMarker(): Change the marker
I also use replace mode for insert row - db.insertWithOnConflict(EVENT_TABLE_NAME, null, value, SQLiteDatabase.CONFLICT_REPLACE); Its will rid of conflict if record is exist already
In DatabaseHelper add UNIQUE INDEX
And call bulkInsert like this:
On the client side,
ContentResolver
supports abulkInsert()
method. Those will not necessarily be processed in a single transaction by theContentProvider
, simply because there may not be any transactions performed by theContentProvider
.I have implemented this in my app and here's the gist of the code that I use.
In my content provider, I have overridden the applyBatch() method and it's a very simple method to override:
The result is given to the next operation because you want to support back references. When I actually want to change stuff in the database in this single transaction I loop over my content and do stuff like this:
You just need to remember to finish by calling:
This will perform your stuff in a single transaction and supports backreferences if you need the id from an earlier insert without issue.
Here an example for bulkInsert:
And in your code something like: