0

I am trying to scan a QR code and pass the value from the scanning result to another activity. I get the result in a SparseArray and extract the most latest scanned value. I am unable to retrieve any string in my second activity. Can anyone tel me if the results in SparseArray are of the string format? If not, how can I receive these values in my second activity in string format?

My MainActivity

@Override
public void receiveDetections(Detector.Detections<Barcode> detections) {
    final SparseArray<Barcode> barcodes = detections.getDetectedItems();
    if (barcodes.size() != 0) {
        Intent intent = new Intent(MainActivity.this, SecondActivity.class);
        intent.putExtra("barcode",barcodes.valueAt(0));
        startActivity(intent);
        finish();
    }
}

My Receiving Activity

Intent intent = getIntent();
String barcode = intent.getStringExtra("barcode");
SMG
  • 95
  • 1
  • 2
  • 11

1 Answers1

1

barcodes.valueAt(0) is returning a Barcode which is implementing Parcelable. In your receiving Activity you should do:

Barcode barcode = (Barcode) intent.getParcelableExtra("barcode");
mromer
  • 1,867
  • 1
  • 13
  • 18