I've this code in Java Android APP that is launched after a camera scan. How Can i go to new activity after a scan?
ActivityResultLauncher<ScanOptions> barLauncher = registerForActivityResult(new ScanContract(), result ->{
if (result.getContents()!=null){
AlertDialog.Builder builder = new AlertDialog.Builder(QRScanActivity.this);
builder.setTitle("Result");
builder.setMessage(result.getContents());
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
dialogInterface.dismiss();
}
}).show();
}
});
Thanks
So you are observing a dialog after scanned something, so the following part is the callback
of your scanning event:
if (result.getContents()!=null){
AlertDialog.Builder builder = new AlertDialog.Builder(QRScanActivity.this);
builder.setTitle("Result");
builder.setMessage(result.getContents());
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
dialogInterface.dismiss();
}
}).show();
}
So all you need to do, is to replace the above code into code that triggers a new Activity:
if (result.getContents() != null) {
Intent intent = new Intent(QRScanActivity.this, NextTargetActivity.class);
// You can also put the scanned result contents using intent.putExtra()
startActivity(intent);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.