使用PICK_CONTACT运行第二个案例

时间:2013-12-07 16:23:59

标签: java android android-intent

我有这个代码将声音作为联系人但是当我插入第二个案例时,如果重复任何想法,java会认出我吗?我已经减轻了代码,以免提前感谢:

代码:

 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));

2 个答案:

答案 0 :(得分:2)

这是问题

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

这就是为什么java看到的重复,这是正确的

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

答案 1 :(得分:1)

PICK_CONTACT1PICK_CONTACT2等于1:

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

所以你有效地做了:

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

你需要制作那些不同的价值观。另外,请确保在每个案例的末尾添加break