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 回答