Birthday Data Is Removed After Updating
<p>I've been trying to add/update birthdays in my contact list. I am able to add birthdays however I have problems when updating the birthday. </p>

<p>Waiting for a couple of seconds after updating, the birthday data disappears/gets deleted.</p>

<p>I've noticed that just after updating the birthday, the "dirty" field gets set to "1", which I guess triggers a syncing mechanism (I am just starting with contacts)</p>

<p>Here are the snippets that I am using</p>

<p>INSERT/ADD BIRTHDAY</p>

<pre><code>    long rawContactId = -1;
    String[] projection = new String[]{ContactsContract.CommonDataKinds.Event.RAW_CONTACT_ID};
    String selection = ContactsContract.CommonDataKinds.Event.CONTACT_ID + "=?";

    String[] selectionArgs = new String[]{
        String.valueOf(bdayContact.getId())
    };

    Cursor c = getContentResolver().query(ContactsContract.Data.CONTENT_URI,
          projection,
          selection,
          selectionArgs, null);
    try {
        if (c.moveToFirst()) {
            rawContactId = c.getLong(0);
        }
    } finally {
        c.close();
    }

     ArrayList&lt;ContentProviderOperation&gt; ops = new ArrayList&lt;ContentProviderOperation&gt;();
     ops.add(ContentProviderOperation.newInsert(Data.CONTENT_URI)
         .withValue(ContactsContract.Data.RAW_CONTACT_ID, rawContactId)
         .withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Event.CONTENT_ITEM_TYPE)
         .withValue(ContactsContract.CommonDataKinds.Event.START_DATE, bday)
         .withValue(ContactsContract.CommonDataKinds.Event.TYPE, ContactsContract.CommonDataKinds.Event.TYPE_BIRTHDAY)
         .build());

     try {
        getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);
    } catch (RemoteException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (OperationApplicationException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
</code></pre>

<p>UPDATE BIRTHDAY</p>

<pre><code>String selection = ContactsContract.CommonDataKinds.Event.CONTACT_ID+"=? AND " +
ContactsContract.CommonDataKinds.Event.MIMETYPE+"=? AND " +
ContactsContract.CommonDataKinds.Event.TYPE+"=?"
                ;
String[] selectionArgs = new String[]{
                           String.valueOf(contacts.get(position).getId()),
                        String.valueOf(ContactsContract.CommonDataKinds.Event.CONTENT_ITEM_TYPE),
                        String.valueOf(ContactsContract.CommonDataKinds.Event.TYPE_BIRTHDAY)
                };

                Cursor cursor = managedQuery(ContactsContract.Data.CONTENT_URI, null, selection, selectionArgs, null);

                if(cursor.moveToFirst()){ 
                    int index = cursor.getColumnIndex(ContactsContract.CommonDataKinds.Event._ID);
                    String eventId = cursor.getString(index);

                    String bday = year+"-"+(monthOfYear+1)+"-"+dayOfMonth;
                }

ArrayList&lt;ContentProviderOperation&gt; ops = new ArrayList&lt;ContentProviderOperation&gt;();
     ops.add(ContentProviderOperation.newUpdate(Data.CONTENT_URI)
         .withSelection(ContactsContract.Data._ID + " = ?", new String[] {eventId})
         .withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Event.CONTENT_ITEM_TYPE)
         .withValue(ContactsContract.CommonDataKinds.Event.START_DATE, bday)
         .withValue(ContactsContract.CommonDataKinds.Event.TYPE, ContactsContract.CommonDataKinds.Event.TYPE_BIRTHDAY)
         .build());

     try {
        getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);
    } catch (RemoteException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (OperationApplicationException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
</code></pre>
