Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8561245
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:27:36+00:00 2026-06-11T16:27:36+00:00

I have 2 buttons that both call startActivityForResult and onActivityResult separately. The first is

  • 0

I have 2 buttons that both call startActivityForResult and onActivityResult separately. The first is a contact picker, the second a picture picker. The first one operates correctly and returns the appropriate contact number to my eddittext as it should. The second starts as it should and allows me to choose a picture from my gallery, but does not return the picture to my imagview as it should. I think its trying to return the data from the first one and cant figure out how to distinguish the first from the second. I’m new to android, still learning, making mistakes, and any help as to where and how I went wrong would be appreciated. My code in question is below.

Button.OnClickListener buttonClickListener3 = new Button.OnClickListener() {
    public void onClick(View contact) {
            Intent intent = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI);
            startActivityForResult(intent, 1);
        }};

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

          if (resultCode == Activity.RESULT_OK) {
                Uri contactData = data.getData();
                Cursor cur = managedQuery(contactData, null, null, null, null);
                ContentResolver contect_resolver = getContentResolver();

                if (cur.moveToFirst()) {
                    String id = cur.getString(cur.getColumnIndexOrThrow(BaseColumns._ID));
                    String name = "";
                    String no = "";

                    Cursor phoneCur = contect_resolver.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,
                            ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = ?", new String[] { id }, null);

                    if (phoneCur.moveToFirst()) {
                        name = phoneCur.getString(phoneCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
                        no = phoneCur.getString(phoneCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
                    }

                    Log.e("Phone no & name :***: ", name + " : " + no);
                    txt.append(name + " : " + no + "/n");

                    id = null;
                    name = null;
                    no = null;
                    phoneCur = null;
                }
                contect_resolver = null;
                cur = null;

            }
    }


    Button.OnClickListener buttonClickListener4 = new Button.OnClickListener() {
      public void onClick(View ChoosePictureButton) {
          Intent choosePictureIntent = new Intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); 
          startActivityForResult(choosePictureIntent, 2);


        }};


        public void onActivityResult2(int requestCode2, int resultCode2, Intent intent) {
          super.onActivityResult(requestCode2, resultCode2, intent);


          if (resultCode2 == RESULT_OK) {
            Uri imageFileUri = intent.getData();

            try {
              BitmapFactory.Options bmpFactoryOptions = new BitmapFactory.Options();
              bmpFactoryOptions.inJustDecodeBounds = true;
              Bitmap bmp = BitmapFactory.decodeStream(getContentResolver().openInputStream(imageFileUri), null, bmpFactoryOptions);
              bmpFactoryOptions.inSampleSize = 2;
              bmpFactoryOptions.inJustDecodeBounds = false;
              bmp = BitmapFactory.decodeStream(getContentResolver().openInputStream(
                      imageFileUri), null, bmpFactoryOptions);

              ChosenImageView.setImageBitmap(bmp);
            } catch (FileNotFoundException e) {
              Log.v("ERROR", e.toString());
            }
          }
        }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T16:27:37+00:00Added an answer on June 11, 2026 at 4:27 pm

    try using a single onActivityResult() like below

    public void onActivityResult(int reqCode, int resultCode, Intent data) {
    super.onActivityResult(reqCode, resultCode, data);
    
          if (resultCode == Activity.RESULT_OK) {
    switch(reqCode)
    {
     case 1:
                Uri contactData = data.getData();
                Cursor cur = managedQuery(contactData, null, null, null, null);
                ContentResolver contect_resolver = getContentResolver();
    
                if (cur.moveToFirst()) {
                    String id = cur.getString(cur.getColumnIndexOrThrow(BaseColumns._ID));
                    String name = "";
                    String no = "";
    
                    Cursor phoneCur = contect_resolver.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,
                            ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = ?", new String[] { id }, null);
    
                    if (phoneCur.moveToFirst()) {
                        name = phoneCur.getString(phoneCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
                        no = phoneCur.getString(phoneCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
                    }
    
                    Log.e("Phone no & name :***: ", name + " : " + no);
                    txt.append(name + " : " + no + "/n");
    
                    id = null;
                    name = null;
                    no = null;
                    phoneCur = null;
                }
                contect_resolver = null;
                cur = null;
    
            }
    }
    break ;
    
    case 2:
            Uri imageFileUri = intent.getData();
    
            try {
              BitmapFactory.Options bmpFactoryOptions = new BitmapFactory.Options();
              bmpFactoryOptions.inJustDecodeBounds = true;
                  Bitmap bmp =  
       BitmapFactory.decodeStream(getContentResolver().openInputStream(imageFileUri), null,  
     bmpFactoryOptions);
              bmpFactoryOptions.inSampleSize = 2;
              bmpFactoryOptions.inJustDecodeBounds = false;
              bmp = BitmapFactory.decodeStream(getContentResolver().openInputStream(
                      imageFileUri), null, bmpFactoryOptions);
    
              ChosenImageView.setImageBitmap(bmp);
            } catch (FileNotFoundException e) {
              Log.v("ERROR", e.toString());
            }
          }
        }
    }
    

    Try using something like the above

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a whole bunch of buttons that all need to have both a
Simply scenario -- I have two buttons both of which call the same controller/action.
I have a WrapPanel that has a button as a child element. Both the
I want to have buttons that kind of act like tabs - they switch
I have two buttons that moves a movieclip up/down the Y-axis. How do I
I have multiple buttons that gets created in a table which all look like
I have ten buttons that each correspond to a different number. I'm looking to
I have 4 buttons that when click starts a new activity class. This works
I have some dynamic buttons that look like this: <input type=button name=button id=button value=Click
I have a bunch of buttons that have a tapGestureRecognizer linked to them, and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.