Bulk insert

suggest change

Here is an example of inserting large chunks of data at once. All the data you want to insert is gathered inside of a ContentValues array.

public int bulkInsert(Uri uri, ContentValues[] values) {
    int count = 0;
    String table = null;

    int uriType = IChatContract.MessageColumns.uriMatcher.match(uri);
    switch (uriType) {
        case IChatContract.MessageColumns.MESSAGES:
            table = IChatContract.MessageColumns.TABLE_NAME;
    try {
        for (ContentValues cv : values) {
            long rowID = mDatabase.insert(table, " ", cv);
            if (rowID <= 0) {
                throw new SQLException("Failed to insert row into " + uri);
        getContext().getContentResolver().notifyChange(uri, null);
        count = values.length;
    } finally {
    return count;

And here is an example of how to use it:

ContentResolver resolver = mContext.getContentResolver();
ContentValues[] valueList = new ContentValues[object.size()];
//add whatever you like to the valueList
resolver.bulkInsert(IChatContract.MessageColumns.CONTENT_URI, valueList);

Feedback about page:

Optional: your email if you want me to get back to you:

Table Of Contents