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

  • SEARCH
  • Home
  • 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 932475
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T20:40:28+00:00 2026-05-15T20:40:28+00:00

so, i’ve been working on this same stupid thing for a while now. some

  • 0

so, i’ve been working on this same stupid thing for a while now. some folks here have helped me get it to the point it is but now i’ve got to move farther forward… but first, my code:

package com.mhe.test.scan;



import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;


public class main extends Activity {
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    Button myScanButton = (Button) findViewById(R.id.myScanButton);

    totalbox = (EditText) findViewById(R.id.tBox);        

    myScanButton.setOnClickListener(new Button.OnClickListener() {
      public void onClick(View v) {
        Intent intent = new Intent("com.google.zxing.client.android.SCAN");
        intent.putExtra("SCAN_MODE", "PRODUCT_MODE");
        startActivityForResult(intent, 0);






      }
    });
  }      
  private EditText totalbox;
  @Override
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
    if (requestCode == 0) {
      if (resultCode == RESULT_OK) {
      final String contents = intent.getStringExtra("SCAN_RESULT");




        if ( totalbox != null );


        totalbox.setText(contents);


        Context context = getApplicationContext();
        CharSequence text = "Successful Scan";
        int duration = Toast.LENGTH_SHORT;
        Toast toast = Toast.makeText(context, text, duration);
        toast.show();

        Button myTotalButton = (Button) findViewById(R.id.myTotalButton);
        myTotalButton.setOnClickListener(new Button.OnClickListener() {
            public void onClick(View view)  {
                Intent pass = new Intent(view.getContext(), Result.class);
                    startActivityForResult(pass, 0);
               }
            });



      } else if (resultCode == RESULT_CANCELED) {

        if ( totalbox != null );
          totalbox.setText("bummer");
      }      

    }




  }
}

so anyhow, what i’d like to happen is upon a successful scan, the result is loaded into the EditText totalbox. then the ‘myTotalButton’ is clicked and will pass the result to the next activity ‘Result.class’. right now i’m just trying to get it to switch to the new activity. If the
Button myTotalButton = (Button) findViewById(R.id.myTotalButton);
myTotalButton.setOnClickListener(new Button.OnClickListener() {
public void onClick(View view) {
Intent pass = new Intent(view.getContext(), Result.class);
startActivityForResult(pass, 0);

code is there, it FCs. otherwise, the rest of it works fine. any suggestions/assistance would be helpful. I feel like i am missing something stupid that i will smack myself for.

  • 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-15T20:40:29+00:00Added an answer on May 15, 2026 at 8:40 pm

    I think I just realized what the problem is.

    The button press activity calls back into the same onActivityResult method it’s called from, and using the same requestCode of 0. This is causing the errors where you attempt to getStringExtra("SCAN_RESULT") because that only exists in the callback from the scan.

    Instead of startActivityForResult(pass, 0); use startActivityForResult(pass, 1); (or whatever digit) and handle it by adding an

    } else if (1 == requestCode) {
        \* your stuff to handle the button result here*\
    }
    

    code section to the existing requestCode if statement (or make it a switch() statement).

    The end result would look something like this:

    @Override 
    public void onActivityResult(int requestCode, int resultCode, Intent intent) {
        if (requestCode == 0) {
            if (resultCode == RESULT_OK) {
                final String contents = intent.getStringExtra("SCAN_RESULT");
                if ( totalbox != null ) {
                    totalbox.setText(contents);
                }
    
                Toast toast = Toast.makeText(getApplicationContext(),
                    "Successful Scan", Toast.LENGTH_SHORT).show();
    
                Button myTotalButton = (Button) findViewById(R.id.myTotalButton);
                myTotalButton.setOnClickListener(new Button.OnClickListener() {
                    public void onClick(View view) {
                        Intent pass = new Intent(view.getContext(), Result.class);
                        startActivityForResult(pass, 1);
                       }
                    });
            } else if (resultCode == RESULT_CANCELED) {
                if ( totalbox != null ) {
                    totalbox.setText("bummer");
                }
            }
        } else if (requestCode == 1) {
            if (resultCode == RESULT_OK) {
                // Do whatever it is you want to do with the returned
                // data from the Result.class activity call
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 484k
  • Answers 484k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer From the looks of it, it uses the standard GZip… May 16, 2026 at 7:32 am
  • Editorial Team
    Editorial Team added an answer When the form is submitted, check the length of the… May 16, 2026 at 7:32 am
  • Editorial Team
    Editorial Team added an answer No, this is not possible. You could come up with… May 16, 2026 at 7:32 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.