Reputation: 21
I have code working for a barcode scanner, but was wondering how could I return the result into a text field in a previous activity?
Upvotes: 1
Views: 354
Reputation: 21
If I get what your are asking, you have a class (maybe an activity?) that implements a barcode scanner and want to put what you get in a textview.
If the barcode scanner it's just a class, you can just return it. If it is an activity, you can call your barcode scanner activity with
Intent i = new Intent(this, YourBarcodeClass.class);
startActivityForResult(i, BarcodeCode);
With this the activity that calls the Barcode Scanner is able to catch a result when the acticity ends with
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
String code = data.getStringExtra("CustomKeyName");
}
In your barcode Scanner activity you have to attach the result to obtain in in onActivityResult when your activity ends, with something like
private void ReturntoActivity(){
Intent data = new Intent();
data.putExtra("CustomKeyName", StringToReturn);
setResult(RESULT_OK, data);
finish();
}
Hope I got what you needed and this helps
Upvotes: 1