How to use onActivityResult (..) if an action is called from a menu

It 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"); } } } 

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 String camera_barcode is null, it is not clear why.

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

Thanks!

+8
android android-intent android-activity menu barcode
source share
2 answers

Complete the action you start for a 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(); 
+17
source share

No matter where you create the intention. If you used the Activity startActivityForResult() method, then you will get the results in onActivityResult() .

0
source share

All Articles