I have an activity, called ScanRouter, that calls ZBar Scanner via startActivityForResult. Once I scan a code, onActivityResult in ScanRouter processes the result, passes the result to another activity via intents and ScanRouter is "finish()".
However, after the result is passed to the new activity, if the back button is pressed, ScanRouter reopens ZBar. If I set ScanRouter to noHistory=true, then onActivityResult doesn't work.
How can I prevent ScanRouter from firing again if the back button is pressed? I thought finish() would remove it from the stack but that is apparently not true. I would like to go back to the activity that originally called ScanRouter rather than ScanRouter itself.
ScanRouter: Portion of the code that matters
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case ZBAR_SCANNER_REQUEST:
case ZBAR_QR_SCANNER_REQUEST:
if (resultCode == RESULT_OK) {
// TODO go back to the caller and give them the result
String value = data.getStringExtra(ZBarConstants.SCAN_RESULT);
**returnIntent(value);**
} else if(resultCode == RESULT_CANCELED && data != null) {
// TODO go back to the caller and give them the error
String error = data.getStringExtra(ZBarConstants.ERROR_INFO);
if(!TextUtils.isEmpty(error)) {
Toast.makeText(this, error, Toast.LENGTH_SHORT).show();
}
}
break;
}
}
protected void returnIntent(String value) {
Intent intent = new Intent(this, Manager.class);
intent.putExtra("operation", caller);
intent.putExtra("code", value);
startActivity(intent);
**this.finish();**
}