1

I have a problem with ZXing activities : When a scan succeeds, it works properly, goes back to parent activity, sets the result in the textfield, but calls the onCreate method of its parent which is very problematic for me.

Here is my result listener :

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
    }
}

The button listener :

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

Would you have any clue ?

4

1 に答える 1

2

いいえ、何かあれば Android が呼び出しonCreate()ますActivity。Android は、必要に応じていつでもアプリを破棄して再作成することがあります。onDestroy()したがって、これに備えてonCreate()適切に実装する必要があります。

于 2012-12-04T11:51:18.433 に答える