Cannot update contact with new fields
<p>I have a problem when try to update existing contact with field which is not exist.
Example:
I successfully create new contact which contain name and email address fields. During create action I use ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI) only for fields which are not empty.</p>

<p>Code for inserting phone field during contact creation (works fine):</p>

<pre><code>if (isNewContact){
    if (!phone.equals("")){
        ops.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
        .withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, id)
        .withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE)
        .withValue(ContactsContract.CommonDataKinds.Phone.NUMBER, phone)
        .withValue(ContactsContract.CommonDataKinds.Phone.TYPE, type)
        .build());
    }
}
</code></pre>

<p>So, now I try to run update process and append to my contact the phone number:</p>

<pre><code>if (isUpdateContact){
    ops.add(ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI)
        .withSelection(ContactsContract.Data.RAW_CONTACT_ID + "=? AND "
                    + ContactsContract.CommonDataKinds.Phone.TYPE
                    + "=? AND " + ContactsContract.Data.MIMETYPE
                    + "=?",
                    new String[] {"" + id, "" + type, 
                    ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE })
        .withValue(ContactsContract.CommonDataKinds.Phone.NUMBER, phone)
        .withValue(ContactsContract.CommonDataKinds.Phone.TYPE, type)
        .build());
}
</code></pre>

<p>In case if during contact creation the phone field was inserted, then update works fine. In case if phone was not inserted, then update does nothing - the field will not be updated. No warnings neither errors in LogCat.</p>

<p>The reason why I do not want to create empty fields on contact creation is because of empty fields crashes Phone application in Samsung Nexus device when I switch to contacts tab with null pointer exception in com.android.contacts.list.ContactListItemView.onMeasure(ContactListItemView.java:350).</p>

<p>So, my question is:
<strong>How during update process to insert a new field if not exist (and how to detect it) OR delete the field if exist but new update value is empty? Is it possible at all or there is another solution to avoid crash of Nexus phone app if fields are empty?</strong></p>

<p>P.S. tried to run newInsert during for already created contact, getting: </p>

<pre><code>mType: 1, mUri: content://com.android.contacts/data, mSelection: null, mExpectedCount: null, mYieldAllowed: false, mValues: data1= mimetype=vnd.android.cursor.item/phone_v2 data2=1, mValuesBackReferences: raw_contact_id=2962, mSelectionArgsBackReferences: null
java.lang.ArrayIndexOutOfBoundsException: asked for back ref 2962 but there are only 1 back refs
at android.content.ContentProviderOperation.backRefToValue(ContentProviderOperation.java:362)
</code></pre>
