-5

I am developing a QR Code app for android. I want to pass whatever I scan into a new activity. This is my QR Code results code,

 public void handleResult(final Result result)
{
    final String scanResult = result.getText();
    AlertDialog.Builder builder  = new AlertDialog.Builder(this);
    builder.setTitle("Scanned Result");
    builder.setPositiveButton("OK", new DialogInterface.OnClickListener()
    {

        @Override
        public void onClick(DialogInterface dialogInterface, int i) {
        scannerView.resumeCameraPreview(MainActivity.this);
        }
    });
    builder.setNeutralButton ("Show", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialogInterface, int i)
        {
            startActivity(new Intent(MainActivity.this, ResultPage.class));
        }
    });
    builder.setMessage(scanResult);
    AlertDialog alert = builder.create();
    alert.show();
}

ResultPage.class is the activity I wish to display the scanned result on to, how do I do this? Edit: My ResultPage.Class is currently empty with only an empty textview. I'd like the output to be in the textview.

D. Anders
  • 11
  • 3

3 Answers3

0
final String scanResult = result.getText();
Intent intent = new Intent(getBaseContext(), ResultPage.class);
intent.putExtra("SCAN_RESULT", scanResult);
startActivity(intent);

Now you can find scanResult in ResultPage activity

String s = getIntent().getStringExtra("SCAN_RESULT");
Ankita
  • 1,129
  • 1
  • 8
  • 15
0

If you have URI then pass that URI using Intent

if you want to pass image itself

Bitmap image= imageView.getDrawingCache();
Bundle extras = new Bundle();
extras.putParcelable("imagebitmap", image);
intent.putExtras(extras);
startActivity(intent);

and in another activity receive like:

Bundle extras = getIntent().getExtras();
Bitmap bmp = (Bitmap) extras.getParcelable("imagebitmap");
image.setImageBitmap(bmp );
DINESH
  • 51
  • 7
0

You will have to pass the Resulted string from MainActivity to ResultPage. For passing the data from one Activity to Another Activity, you can use Bundle.

Here is the code for sending data to another Activity:

builder.setNeutralButton ("Show", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialogInterface, int i)
        {
            Intent intent = new Intent(MainActivity.this,ResultPage.class);
            Bundle bundle = new Bundle();
            bundle.putString("RESULT",scanResult);
            intent.putExtra(bundle);
            startActivity(intent);
        }
    });

And now you can get this result to ResultPage Activity. Here is the code for getting data.

Bundle bundle = getIntent().getExtras();
String scanResult = bundle.getString("RESULT");

Now you can Display your scanResult.

Ghulam Moinul Quadir
  • 1,638
  • 1
  • 12
  • 17