I have a main activity, in which I create two tabs.
The first tab includes the zxing barcodescanner, and the second one a frame layout with a texteditfield where the user can enter a barcode with the keypad.
Both classes are started as acitivities in their own tabs.
I want to pass the barcode - which is scanned either by camera or entered manually - back to my main activity. Usually passing results from subactivities to parentactivities is done by starting the subactivity with "startActivityForResult". The parentactivity handels the result in the "onActivityResult" method.
But how can this be done with activities in tabs?
Using "setResult(RESULT_OK, intent) and finish() doesn't work, and it quits the mainactivity. I tried debugging, but I coudln't get behind it.
Here is my mainactivity:
Using java Syntax Highlighting
- public class ProductSearchActivity extends TabActivity{
- private TabHost mTabHost;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.productsearch);
- Window window = getWindow();
- window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
- mTabHost = getTabHost();
- TabSpec ts1 = mTabHost.newTabSpec("UseCamera");
- ts1.setIndicator("Use Camera");
- Intent intent = new Intent(this, CaptureActivity.class);
- ts1.setContent(intent);
- TabSpec ts2 = mTabHost.newTabSpec("UseKeyboard");
- ts2.setIndicator("Use Keyboard");
- Intent intent2 = new Intent(this, ManualInputActivity.class);
- ts2.setContent(intent2);
- mTabHost.addTab(ts1);
- mTabHost.addTab(ts2);
- }
- public void onActivityResult(int requestCode, int resultCode, Intent intent) {
- if (requestCode == 0) {
- if (resultCode == RESULT_OK) {
- String barcode = intent.getStringExtra("SCAN_RESULT");
- String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
- // Handle successful scan
- } else if (resultCode == RESULT_CANCELED) {
- // Handle cancel
- }
- }
- }
- }
Parsed in 0.012 seconds, using GeSHi 1.0.8.4
and the second activity where the barcode can be entered manually:
Using java Syntax Highlighting
- public final class ManualInputActivity extends Activity {
- @Override
- protected void onCreate(Bundle icicle) {
- super.onCreate(icicle);
- setContentView(R.layout.manual_input_tab);
- Button goButton = (Button) findViewById(R.id.goButton);
- goButton.setOnClickListener(mDoneListener);
- RadioButton rButton = (RadioButton) findViewById(R.id.RadioButton01);
- rButton.setChecked(true);
- }
- private final Button.OnClickListener mDoneListener = new Button.OnClickListener() {
- public void onClick(View view) {
- EditText editor = (EditText) findViewById(R.id.barcodeInputEditText);
- Intent result = new Intent(getIntent().getAction());
- String barcode = editor.getText().toString();
- result.putExtra("BARCODE", barcode);
- setResult(RESULT_OK, result);
- finish();
- }
- };
- }
Parsed in 0.012 seconds, using GeSHi 1.0.8.4
Thx for helping!