如果从菜单调用活动,如何使用 onActivityResult(..)
这是我的问题:
class main extends menuActivity{
//
..
//
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == 0)
camera_barcode = INTENT.getStringExtra("SCAN_RESULT");
}
}
}
INTENT 是在 menuActivity 类中创建的:
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_barcode 为空,无法理解为什么。
问:如果我想扫描一维条码而不是 QR_CODE_MODE? R:cameraScan.putExtra("SCAN_MODE", "Product_MODE");
谢谢你!!
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!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
完成您正在开始的活动,结果如下
Finish the activity you are starting for result like this
在哪里创建意图并不重要。如果您使用了 Activity 的
startActivityForResult()
方法,那么您将在onActivityResult()
函数中收到结果。It doesn't matter where you create the intent. If you've used Activity's
startActivityForResult()
method, then you'll receive results inonActivityResult()
function.