Problem with android agenda

Asked

Viewed 27 times

1

I’m starting an interview to get a contact in the contact list:

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

But when I start the Internet and return to the screen, it returns to the Internet again, as if I had clicked again to get the contact. only then can I "get out" of the internet.

Man 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;
        }
    }
  • 1

    You are using java or c#?

  • 1

    I’m using c# in Xamarin

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.