Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I think I just realized what the problem is.</p> <p>The button press activity calls back into the same <code>onActivityResult</code> method it's called from, and using the same requestCode of 0. This is causing the errors where you attempt to <code>getStringExtra("SCAN_RESULT")</code> because that only exists in the callback from the scan.</p> <p>Instead of <code>startActivityForResult(pass, 0);</code> use <code>startActivityForResult(pass, 1);</code> (or whatever digit) and handle it by adding an </p> <pre><code>} else if (1 == requestCode) { \* your stuff to handle the button result here*\ } </code></pre> <p>code section to the existing requestCode if statement (or make it a switch() statement).</p> <p>The end result would look something like this:</p> <pre><code>@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 } } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload