0
    @Override
public void onClick(View v) {
    if (v.getId() == R.id.scan_button) {
        Log.i("result", "START SCAN");
        IntentIntegrator scanIntegrator = new IntentIntegrator(
                BarcodeScan.this);
        scanIntegrator.initiateScan();

    }
}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
    super.startActivityForResult(intent, resultCode);
    Log.i("result", "Result Out");
    if (requestCode == 0) {
        IntentResult scanningResult = IntentIntegrator.parseActivityResult(
                requestCode, resultCode, intent);
        if (resultCode == RESULT_OK) {
            if (scanningResult != null) {
                String scanContent = scanningResult.getContents();
                DatabaseAdapter mDbHelper = new DatabaseAdapter(this);
                mDbHelper.createDatabase();
                mDbHelper.open();
                BookController bc = new BookController(mDbHelper.open());
                Log.i("result", scanContent);
                String bookID = bc.getBookIDByBarcode(scanContent);
                System.out.println(bookID);
                intent = new Intent(context, ReserveBook.class);
                intent.putExtra("BookID", bookID);
                startActivity(intent);
                this.finish();
            } else {
                Toast toast = Toast.makeText(getApplicationContext(),
                        "No scan data received!", Toast.LENGTH_SHORT);
                toast.show();
            }
        } else if (resultCode == RESULT_CANCELED) {
            // Handle cancel
            Log.i("App", "Scan unsuccessful");
        }
    }
}

I am implementing Zxing Barcode Scanning into my app, I am able to scan the barcode, but after scan the apps was stop. In the LogCat, the START SCAN got printed out. After that the app close.

1 Answers1

0

Don't call super.startActivityForResult(intent, resultCode); Remove this line.

VJ Vélan Solutions
  • 6,434
  • 5
  • 49
  • 63
  • same result, after scan the app closed. – user3687053 Nov 02 '14 at 06:41
  • after you removed that line, do you atleast see Log.i("result", "Result Out"); printed out on your debug console? – VJ Vélan Solutions Nov 02 '14 at 13:27
  • remove everything inside if (scanningResult != null) { } except for Log.i("result", scanContent); statement. May be your ReserveBook activity does not start as you except or database is not opening. anyways, if you can see Log.i("result", "Result Out"); and Log.i("result", scanContent); printed out, then you can claim that onActivityResult() is called correctly. – VJ Vélan Solutions Nov 02 '14 at 13:32
  • I don't see Result Out, it seems never call onActivityResult() – user3687053 Nov 03 '14 at 08:23
  • Replace new IntentIntegrator(BarcodeScan.this); with new IntentIntegrator(this); Look at the working example here: http://stackoverflow.com/questions/11015807/android-zxing-barcode-scan-successful-but-not-returning-from-activity – VJ Vélan Solutions Nov 03 '14 at 11:28
  • can you please check my [question](https://stackoverflow.com/q/64784906/8868582) related to it? – Faisal Qayyum Nov 11 '20 at 10:52