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 3962142
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T03:03:39+00:00 2026-05-20T03:03:39+00:00

So I have a very simple app I am working on. It’s purpose is

  • 0

So I have a very simple app I am working on. It’s purpose is to collect asset data from 1 pc, and 1 or 2 monitors.
My form contains 3 edittext views, and 3 buttons (one for each asset I am collecting data for). The buttons invoke startActivityForResult for the barcode scanner, then I want to pass the result to the associated edittext view based on which button was pressed (example: press “scan” button to the right of “Asset – PC” edittext, scan and return data to it’s associated edittext. Then if you press the button “scan” thats next to the “Asset – Mon1” edittext, return data to “Asset – Mon1” edittext…. and so on…)

With the code I have here, all the items work, just not as intended. Pressing any of the “scan” buttons always returns the result to the first edittext view “Asset – PC”.

public class TestShit extends Activity {

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
}

    public void assetPcClick(View view) {
        Intent intent1 = new Intent("com.google.zxing.client.android.SCAN");
        intent1.setPackage("com.google.zxing.client.android");
        intent1.putExtra("SCAN_MODE", "ONE_D_MODE");
        startActivityForResult(intent1, 0);
    }   

    public void onActivityResult(int requestCode, int resultCode, Intent intent) {
        if (requestCode == 0) {
            if (resultCode == RESULT_OK) {
                String contents1 = intent.getStringExtra("SCAN_RESULT");
                String format1 = intent.getStringExtra("SCAN_RESULT_FORMAT");
                EditText assetPC = (EditText) findViewById(R.id.assetPC);
                assetPC.setText(contents1);
            } else if (resultCode == RESULT_CANCELED) {
                // Handle cancel
            }
        }
    }

    public void assetMon1Click(View view) {
        Intent intent2 = new Intent("com.google.zxing.client.android.SCAN");
        intent2.setPackage("com.google.zxing.client.android");
        intent2.putExtra("SCAN_MODE", "ONE_D_MODE");
        startActivityForResult(intent2, 0);
    }   

    public void onActivityResult2(int requestCode, int resultCode, Intent intent2) {
        if (requestCode == 0) {
            if (resultCode == RESULT_OK) {
                String contents2 = intent2.getStringExtra("SCAN_RESULT");
                String format2 = intent2.getStringExtra("SCAN_RESULT_FORMAT");
                EditText assetMon1 = (EditText) findViewById(R.id.assetMon1);
                assetMon1.setText(contents2);
            } else if (resultCode == RESULT_CANCELED) {
                // Handle cancel
            }
        }
    }

    public void assetMon2Click(View view) {
        Intent intent3 = new Intent("com.google.zxing.client.android.SCAN");
        intent3.setPackage("com.google.zxing.client.android");
        intent3.putExtra("SCAN_MODE", "ONE_D_MODE");
        startActivityForResult(intent3, 0);
    }   

    public void onActivityResult3(int requestCode, int resultCode, Intent intent3) {
        if (requestCode == 0) {
            if (resultCode == RESULT_OK) {
                String contents3 = intent3.getStringExtra("SCAN_RESULT");
                String format3 = intent3.getStringExtra("SCAN_RESULT_FORMAT");
                EditText assetMon2 = (EditText) findViewById(R.id.assetMon2);
                assetMon2.setText(contents3);
            } else if (resultCode == RESULT_CANCELED) {
                // Handle cancel
            }
        }
    }

}

Any suggestions on how I can better manage my multiple “ActivityForResult” and “onActivityResult” ‘s ?


My fix, thank you for all your help!

public void onActivityResult(int requestCode, int resultCode, Intent intent) {
        if (requestCode == 0) {
            if (resultCode == RESULT_OK) {
                String contents1 = intent.getStringExtra("SCAN_RESULT");
                String format1 = intent.getStringExtra("SCAN_RESULT_FORMAT");
                EditText assetPC = (EditText) findViewById(R.id.assetPC);
                assetPC.setText(contents1);
            } else if (resultCode == RESULT_CANCELED) {
                // Handle cancel
            }
        }
        if (requestCode == 1) {
            if (resultCode == RESULT_OK) {
                String contents1 = intent.getStringExtra("SCAN_RESULT");
                String format1 = intent.getStringExtra("SCAN_RESULT_FORMAT");
                EditText assetMon1 = (EditText) findViewById(R.id.assetMon1);
                assetMon1.setText(contents1);
            } else if (resultCode == RESULT_CANCELED) {
                // Handle cancel
            }
        }
        if (requestCode == 2) {
            if (resultCode == RESULT_OK) {
                String contents1 = intent.getStringExtra("SCAN_RESULT");
                String format1 = intent.getStringExtra("SCAN_RESULT_FORMAT");
                EditText assetMon2 = (EditText) findViewById(R.id.assetMon2);
                assetMon2.setText(contents1);
            } else if (resultCode == RESULT_CANCELED) {
                // Handle cancel
            }
        }
    }    
  • 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-05-20T03:03:39+00:00Added an answer on May 20, 2026 at 3:03 am

    In your startActivityForResult, don’t use 0’s on both calls… use different numbers like 0 & 1… then you can implement a switch in your onActivityResult method with the requestCode. If the requestCode = 0 then the first method has returned, if it is 1, then the second has returned. This should be the same for more calls.

    public void onActivityResult(int requestCode, int resultCode, Intent intent){
        switch(requestCode){
            case 0: // Do your stuff here...
            break;
            case 1: // Do your other stuff here...
            break;
            case etc:
            break;
        }
    }
    

    The calls should be something like this then:
    (For the first time)

    startActivityForResult(intent1, 0);
    

    (For the second time)

    startActivityForResult(intent2, 1);
    

    (for the third time)

    startActivityForResult(intent3, 2);
    

    (for the nth time)

    startActivityForResult(intentn, n - 1);
    

    Or, you could declare static int values to use, instead of the more unrecognisable int values.

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

Sidebar

Related Questions

I'm working on a very simple iPhone app, that in the end will have
I have very simple select like this: SELECT * FROM table WHERE column1 IN
I have a very simple WPF application in which I am using data binding
I have a very simple case that I think would benefit from using templates
i have very simple problem. I need to create model, that represent element of
I have a very simple problem which requires a very quick and simple solution
I have a very simple bit of script that changes the status of an
I have a very simple TCP server written in C. It runs indefinitely, waiting
I have a very simple Java RMI Server that looks like the following: import
I have a very simple ASP.Net page that acts as a front end for

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.