开发者

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

开发者 https://www.devze.com 2023-03-21 21:08 出处:网络
This is my problem: class main extends menuActivity{ // .. // public void onActivityResult(int requestCode, int resultCode, Intent data) {

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 t开发者_C百科hat 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!!


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();


It doesn't matter where you create the intent. If you've used Activity's startActivityForResult() method, then you'll receive results in onActivityResult() function.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号