title: Scan Barcode inside Fragment
body: <p>I want to Scan a Barcode inside my Fragment. If I click on the Scan button the barcode Scanner pops up and scans the Barcode. But I cannot get the scanned text. Whats the problem with my onActivityResult method?</p>
  
  <p>Background: Ive got two different scan buttons in my application. the first one scans qrcodes and is located in my <code>MainActivity</code>. It works fine and also my <code>onActivityResult</code>method works good. 
  The second scan button is located in my AddDataFragment. With this button I want to scan Serials, based on regular barcodes. So I have 2 scan events and one <code>onActivityResult</code>....</p>
  
  <p>EDIT: I changed my old false Code to my (hopefully) better Code.</p>
  
  <p>This is the <code>onActivityResult</code>Code in my <code>MainActivity</code>. How do I get the scanned string (scannedResult) from my <code>MainActivity</code>to my <code>AddDataFragment</code>?</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code> public void onActivityResult(int requestCode, int resultCode, Intent intent) {
          super.onActivityResult(requestCode, resultCode, intent);
          if (requestCode == 0) {
              if (resultCode == RESULT_OK) {
                  String scanContent = intent.getStringExtra("SCAN_RESULT");
                  String scanFormat = intent.getStringExtra("SCAN_RESULT_FORMAT");
                  Log.d("INHALT", scanContent);
                  Log.d("FORMAT", scanFormat);
                  if (scanFormat == "QR_CODE"){
                      String [] Split = scanContent.split("\\s");
                      String product = Split[0];
                      String label = Split[1];
                      
  
                      mydb.insertData(product, label);
                  } else {
                      scannedResult = scanContent;
                  }
  
  
  
              } else if (resultCode == RESULT_CANCELED) {
                  // Handle cancel
              }
          }
  
  
          Fragment fragment;
          FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
          fragment = new ListViewFragment();
          ft.replace(R.id.container, fragment);
          ft.commitAllowingStateLoss();
      }</code></pre>
  </div>
  </div>
  </p>
  
  <p>This is the method I call in my <code>AddDataFragment</code></p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>        inputSerial = (EditText) view.findViewById(R.id.editText_serial);
          ImageButton ib = (ImageButton) view.findViewById(R.id.button_scan_serial);
          ib.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View view) {
                  Intent intent = new Intent("com.google.zxing.client.android.SCAN");
                  intent.putExtra("SCAN_FORMATS", "CODE_39,CODE_93,CODE_128,DATA_MATRIX,ITF,CODABAR,EAN_13,EAN_8,UPC_A");
                  startActivityForResult(intent, 0);
  
              }
          });</code></pre>
  </div>
  </div>
  </p>
  
  <p>But it seems that the call of <code>onActivityResult</code>isnt working because I dont get the Log entrys after scanning a regular Barcode. (No crash or Error Message)</p>