ZXing在扫描后调用父母onCreate

时间:2012-12-04 11:40:48

标签: android zxing oncreate

我遇到ZXing活动的问题:当扫描成功时,它正常工作,返回父活动,在文本字段中设置结果,但调用其父级的onCreate方法,这对我来说非常有问题。

这是我的结果监听器:

public void onActivityResult(int requestCode, int resultCode, Intent intent) {
    super.onActivityResult(requestCode, resultCode, intent);

    IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
    if(resultCode == RESULT_OK) {
        if (scanResult != null) {
            String ean = scanResult.getContents();
            eanEdit.setText(ean);
        }
    } else {
        // Nothing
    }
}

按钮监听器:

public void addScanButtonListener() {
    scanButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            IntentIntegrator integrator = new IntentIntegrator(MainActivity.this);
            integrator.addExtra("SCAN_WIDTH", 800);
            integrator.addExtra("SCAN_HEIGHT", 200);
            integrator.addExtra("RESULT_DISPLAY_DURATION_MS", 0L);
            integrator.addExtra("SCAN_FORMATS", "EAN_13,EAN_8");
            integrator.addExtra("SAVE_HISTORY", false);
            integrator.addExtra("PROMPT_MESSAGE", "Scan please");
            integrator.initiateScan(IntentIntegrator.PRODUCT_CODE_TYPES);
        }
    });
}

你有什么线索吗?

1 个答案:

答案 0 :(得分:1)

不,如果有的话,Android会在onCreate()中调用Activity。如果需要,Android可以随时销毁并重新创建您的应用。因此,您需要适当地实施onDestroy()onCreate()以便为此做好准备。