Gapp Aiello
Gapp Aiello

Reputation: 182

Run the second case with PICK_CONTACT

I have this code to put sound in as a contact but when I insert the second case java recognize me if a duplicate any ideas? I've lightened the code so as not to confuse thanks in advance:

code:

 static final int PICK_CONTACT1 = 1;
  static final int PICK_CONTACT2 = 1;



// first  Intent intent = new Intent(Intent.ACTION_PICK,
    ContactsContract.Contacts.CONTENT_URI);
     startActivityForResult(intent, PICK_CONTACT1);

// second

Intent intent = new Intent(Intent.ACTION_PICK,
    ContactsContract.Contacts.CONTENT_URI);
     startActivityForResult(intent, PICK_CONTACT2);




@Override
       public void onActivityResult(int reqCode, int resultCode, Intent data) {
      super.onActivityResult(reqCode, resultCode, data);

       switch (reqCode) {
       case (PICK_CONTACT1):
       if (resultCode == Activity.RESULT_OK) {

        Uri contactData = data.getData();
         Cursor c = managedQuery(contactData, null, null, null, null);
          if (c.moveToFirst()) { //ecc...




 case (PICK_CONTACT2):
       if (resultCode == Activity.RESULT_OK) {

        Uri contactData = data.getData();
         Cursor c = managedQuery(contactData, null, null, null, null);
          if (c.moveToFirst()) {

           String id = c
            .getString(c.getColumnIndexOrThrow(ContactsContract.Contacts._ID));

Upvotes: 0

Views: 39

Answers (2)

Tom Tsagkatos
Tom Tsagkatos

Reputation: 1494

here is the problem

static final int PICK_CONTACT1 = 1;
static final int PICK_CONTACT2 = 1;

that's why java sees is as duplicate, here is the correct one

static final int PICK_CONTACT1 = 1;
static final int PICK_CONTACT2 = 2;

Upvotes: 2

jprofitt
jprofitt

Reputation: 10964

You have both PICK_CONTACT1 and PICK_CONTACT2 equal to 1:

static final int PICK_CONTACT1 = 1;
static final int PICK_CONTACT2 = 1;

So you're effectively doing:

switch(reqCode) {
    case 1:
        //stuff
    case 1:
        //stuff
}

You'll need to make those different values. Also, make sure you add a break at the end of each case.

Upvotes: 1

Related Questions