Problem with the android calendar

1

I'm starting an attempt to pick up a contact from the contact list:

if (AceitouContacts)
            {
                Intent intent = new Intent(Intent.ActionPick, ContactsContract.CommonDataKinds.Phone.ContentUri);
                StartActivityForResult(intent, 101);
            }

But when I start to try and return to the screen, it returns to the try again, as if I had clicked again to get the contact. only then I can "exit" the attempt.

My OnActivityResult:

public override void OnActivityResult(int requestCode, [GeneratedEnum] Result resultCode, Intent data)
    {
        base.OnActivityResult(requestCode, resultCode, data);

        switch (requestCode)
        {
            case (101):

                if (resultCode == Result.Ok)
                {

                    var contactData = data.Data;

                    String[] projection = new String[] {    ContactsContract.Contacts.InterfaceConsts.DisplayName,
                                                            ContactsContract.CommonDataKinds.Phone.Number,
                                                            ContactsContract.CommonDataKinds.Email.Address};

                    var cursor = Activity.ContentResolver.Query(contactData, projection, null, null, null);

                    int indexName = cursor.GetColumnIndexOrThrow(ContactsContract.Contacts.InterfaceConsts.DisplayName);
                    int indexNumber = cursor.GetColumnIndexOrThrow(ContactsContract.CommonDataKinds.Phone.Number);
                    int indexEmail = cursor.GetColumnIndexOrThrow(ContactsContract.CommonDataKinds.Email.Address);

                    String name = "";
                    String number = "";
                    String email = "";

                    if (cursor != null)
                    {
                        if (cursor.MoveToNext())
                        {
                            name = cursor.GetString(0);
                            number = cursor.GetString(1);
                            email = cursor.GetString(2);
                        }
                        cursor.Close();
                    }

                    if (name != null && name != "")
                    {
                        editTextNomeAnjoDaGuarda.Text = name;
                    }

                    if(number != null && number != "")
                    {
                        int lenght = number.Replace("+55", "").Replace(" ", "").Replace("-", "").Length;

                        if(lenght < 11 || lenght > 11)
                        {
                            DialogHelper.showDialogError(Activity, "Ops!","Insira um número válido.");
                        }
                        else
                        {
                            editTextCelularAnjoDaGuarda.Text = number.Replace("+55", "").Replace(" ", "").Replace("-", "");
                        }
                    }

                    if(email != null && email != "")
                    {
                        editTextEmailAnjoDaGuarda.Text = email;
                    }
                }
                break;
        }
    }
    
asked by anonymous 18.06.2018 / 23:22

0 answers