本文介绍了如何使用onActivityResult(..)如果该活动是从菜单调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的问题:
class main extends menuActivity{
//
..
//
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == 0)
camera_barcode = INTENT.getStringExtra("SCAN_RESULT");
}
}
}
做的目的是在menuActivity类创建的:
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);
//
}
}
现在的问题是,该字符串camera_bar code为null,不明白为什么。
The problem is that the String camera_barcode is null, can't understand why.
问:如果代替QR_ code_MODE我要扫描一维条码codeS?R:cameraScan.putExtra(SCAN_MODE,PRODUCT_MODE);
Q: if instead of QR_CODE_MODE I want to scan 1d barcodes?R: cameraScan.putExtra("SCAN_MODE", "PRODUCT_MODE");
感谢你!
推荐答案
完成你开始对结果像这样的活动
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();
这篇关于如何使用onActivityResult(..)如果该活动是从菜单调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!