I have the following code to insert contentValues in Database. I use the SQLitedatabase method insert() to insert values in database as follows:

```
    public static final String ID = "id";
    public boolean replaceOrUpdate(DBListener dbListener,final String sTable, ContentValues[] contentValues,String tag) {
    this.mDbListener=dbListener;

    if(mDatabase == null) {
        openDB();
    }
    mDatabase.beginTransaction();
    try {
        int count = contentValues.length;
        for (int i=0; i<count;i++) {
            ContentValues value = contentValues[i];
            long id = mDatabase.replaceOrThrow(sTable,null,value);
        }
        mDatabase.setTransactionSuccessful();
        mDbListener.onCompleteInsertion(tag);
    }catch (Exception e) {
        Log.v("Exception = " , " " + e.toString());
        e.printStackTrace();
    }finally {
        mDatabase.endTransaction();
    }
    return true;
}

public ArrayList<String> getAllPlacesIDs()
{
    ArrayList<String> ids = new ArrayList<String>();
    try
    {
        if(mDatabase==null || !mDatabase.isOpen())
        {
            openDB();
        }
        String query="SELECT "+DBUtil.ID+" FROM "+TABLE_MERCHANT_STORES;
        Cursor  cursor = mDatabase.rawQuery(query,null);
        for(cursor.moveToFirst();!cursor.isAfterLast();cursor.moveToNext())
        {
            ids.add(cursor.getString(cursor.getColumnIndex(DBUtil.ID)));
        }
        cursor.close();
    }catch(SQLException sqx)
    {
        sqx.printStackTrace();
    }
    catch(Exception ex)
    {
        ex.printStackTrace();
    }
    finally
    {

    }
    return ids;

}

```

The table is created as follows:

```
db.execSQL("CREATE TABLE IF NOT EXISTS "+
            TABLE_MERCHANT_STORES +" ("+
            AUTO_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "+
            DBUtil.ID       +" INTEGER NOT NULL UNIQUE, "+...)

```

This code works fine on pre-lollipop devices, but the insertion does not work as expected on lollipop. It seems to get stuck at certain values and continues inserting the missing values in the table. After insertion when I print all the values they appear in ascending order with a few intermediate values missing. The id values stored in the table are 

1
2
3
4
5
7
11
13
14
15
16
17
19

whereas the values that gets inserted (expected) on pre-lollipop are:

514
533
531
312
434
162
253
252 
151
344
153
160
658

The error pattern seen on lollipop devices is that when an id is inserted in the table, it seems that the query continues inserting in the gaps between last greatest ID and current greatest id as long as the next id it receives is not greater than the current id inserted. Is this a bug in lollipop sqlite? Or is it something specific to my device? There is no such logic implemented in the app. How do I correct this? Is it because the string being used is id? It works fine on pre-lollipop devices, but works wrongly on lollipop.

EDIT:

The way I am adding the values is as follows:

```
private void insertIntoDB() {
    int count = jsonArray.length();
    ContentValues[] values = new ContentValues[count];

    for(int i=0;i<count;i++){
        JSONObject storeObject=jsonArray.getJSONObject(i);
        if(storeObject!=null){
            ContentValues value=new ContentValues();
            value.put(DBUtil.ID, storeObject.getInt("id"));
            mArrId.add(storeObject.getInt("id")+"");
            value.put("place_parent", storeObject.getInt("place_parent"));
        }
    }
    Cursor c1=new MylocalCursorLoader(mContext, "Delete from " + DBUtil.TABLE_MERCHANT_STORES).loadInBackground();
                if(c1!=null){
                    DBUtil dbUtil = DBUtil.getInstance(mContext.getApplicationContext());
                    dbUtil.replaceOrUpdate(this, DBUtil.TABLE_MERCHANT_STORES, values,"merchant-stores");
                    mProgess.setVisibility(View.VISIBLE);
                }
}

```

MyLocalCursorLoader is a class extending CursorLoader. The storeObject.getInt("id") has values in the order of 

514
533
531
312
434
162
253
252 
151
344
153
160
658