Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to use onActivityResult(..) if the activity is called from a menu

This is my problem:

class main extends menuActivity{
  //
  ..
  //
  public void onActivityResult(int requestCode, int resultCode, Intent data) {
     if (resultCode == 0) 
        camera_barcode = INTENT.getStringExtra("SCAN_RESULT");
     }
  }
}

the INTENT is created in the menuActivity class:

public class menuActivity extends Activity {

    public INTENT;
@Override
public boolean onCreateOptionsMenu(Menu menu) {

}

@Override
public boolean onOptionsItemSelected(MenuItem item) {

       //
       INTENT = new Intent("com.google.zxing.client.android.SCAN");
       INTENT.putExtra("SCAN_MODE", "QR_CODE_MODE");
       startActivityForResult(INTENT, 0);
       //
    }
} 

The problem is that the String camera_barcode is null, can't understand why.

Q: if instead of QR_CODE_MODE I want to scan 1d barcodes? R: cameraScan.putExtra("SCAN_MODE", "PRODUCT_MODE");

Thank you!!

like image 820
MataMix Avatar asked Jul 21 '11 17:07

MataMix


1 Answers

Finish the activity you are starting for result like this

  Bundle b = new Bundle();
  b.putString(key, value);
  Intent i = getIntent(); //gets the intent that called this intent
  i.putExtras(b);
  setResult(Activity.RESULT_OK, i);
  finish();
like image 179
Nikola Despotoski Avatar answered Nov 15 '22 05:11

Nikola Despotoski