0

hi i am currently working on QR code scanner. I want to ask if it is possible to open another activity after the QR code have been scanned rather than getting it displayed as a toast? below is my scanner file code

@Override

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);


    mtexthello=(TextView)findViewById(R.id.textview_hello);
    scanbtn=(Button)findViewById(R.id.btn1) ;
    final  Activity activity=this;

    scanbtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            IntentIntegrator l=new IntentIntegrator(activity);
            l.setDesiredBarcodeFormats(l.QR_CODE_TYPES);
            l.setPrompt("scan");
            l.setCameraId(0);
            l.setBeepEnabled(false);
            l.setBarcodeImageEnabled(false);
            l.initiateScan();

        }
    });
}

@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
    IntentResult res= IntentIntegrator.parseActivityResult(requestCode, resultCode,data);
    if(res!=null)
     if(res.getContents()==null)
     {
         Toast.makeText(this,"u cancelled scanning",Toast.LENGTH_LONG).show();

     }
     else
     {

         Intent intent = new Intent(MainActivity.this, LoginActivity.class);
         startActivity(intent);
        // Toast.makeText(this,res.getContents(),Toast.LENGTH_LONG).show();

     }




    super.onActivityResult(requestCode, resultCode, data);
    }
}
Tamir Abutbul
  • 7,301
  • 7
  • 25
  • 53
WiLc0
  • 11
  • 3

1 Answers1

0

At a first reading it sounds as if the issue is how you're attempting to start the next activity, if not the activity itself.

Start a new app, and use a simple Button as the trigger for the new activity. Once you have the syntax and requirements correct there, apply what you've learned to the QR app.

If you're able to get the Toast to display from your existing code, then your difficulty has nothing to do with the QR code.

Maybe what you really need is to look at something like this (Start an Activity with a parameter) where you pass a parameter to the second activity.

Fachtna Roe
  • 116
  • 2