请问大拿们,ZXING扫描二维码要扫2次才跳转到我自己的Activity是怎么回事?

具体描述:对准二维码或条形码扫描后,又跳转回扫描框界面(应该跳转到我的Activity),第二次扫描就跳转到我的Activity成功了;另外,我发现在扫描框出现后,我不去扫描选择点击返回,同样需要点击2遍才回到MainActivity。这是怎么回事,如何解决啊。(好像是ZXING3.2.1自带的问题,求解决)

以下是我的代码:

MainActivity下代码(是调用CaptureActivity获取到result,然后传递回我的MainActivity再跳转到ScanResultActivity获取结果):

intent.setClass(MainActivity.this, CaptureActivity.class);
startActivityForResult(intent, 0);
protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data);

if (resultCode == RESULT_OK) { final String result = data.getExtras().getString("result");
//定义一个handler对象 final android.os.Handler handler = new android.os.Handler() { public void handleMessage(Message msg) { if (msg.what == 1) {
RetValue retValue = (RetValue) msg.obj; //如果登录成功,转到查询明细 Intent intent = new Intent(MainActivity.this,ScanResultActivity.class);
Bundle data = new Bundle();
data.putString("totalqnty", retValue.getRetData().get(0).toString());
data.putString("detail", retValue.getRetData().get(1).toString()); //以下是查询明细所需条件 data.putString("bspno", result.toString());

        intent.putExtras(data);
        startActivity(intent);
    }
}

}; //定义一个线程,在线程中运行webservice //开始验证登录帐号 new Thread(new Runnable() { @Override public void run() {
Message msg = new Message(); try {

        RetValue retScanDetail = ws.GetBoxInfo(result.toString());
        msg.obj = retScanDetail; //查询成功,继续获取相关的配置  if (Boolean.valueOf(retScanDetail.getRetValue().toString())) {
            msg.what = 1;

        } else {
            msg.what = 0;
        }
    } catch (Exception e) {
        msg.what = 0;
        RetValue retScanDetail = new RetValue();
        retScanDetail.setRetMsg(e.getMessage());
    } handler.sendMessage(msg);

}

}).start();

}}

zxing CaptureActivity中 handleDecode下代码:

public void handleDecode(Result rawResult, Bitmap barcode, float scaleFactor) { inactivityTimer.onActivity(); beepManager.playBeepSoundAndVibrate();

Intent resultIntent = new Intent();
Bundle bundle = new Bundle();
bundle.putString("result", rawResult.getText());
resultIntent.putExtras(bundle); this.setResult(RESULT_OK, resultIntent);
CaptureActivity.this.finish();}

1个回答

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!