startActivityForResult in a Tab possible?

Put your problem here if it does not fit any of the other categories.

startActivityForResult in a Tab possible?

Postby skel_ » Fri Nov 06, 2009 6:15 pm

Hi guys,

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:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. public class ProductSearchActivity extends TabActivity{
  3.  
  4.        
  5.  
  6.         private TabHost mTabHost;
  7.  
  8.        
  9.  
  10.         @Override
  11.  
  12.         protected void onCreate(Bundle savedInstanceState) {
  13.  
  14.                 super.onCreate(savedInstanceState);
  15.  
  16.                 setContentView(R.layout.productsearch);
  17.  
  18.                 Window window = getWindow();
  19.  
  20.             window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);  
  21.  
  22.  
  23.  
  24.             mTabHost = getTabHost();
  25.  
  26.  
  27.  
  28.             TabSpec ts1 = mTabHost.newTabSpec("UseCamera");
  29.  
  30.             ts1.setIndicator("Use Camera");
  31.  
  32.             Intent intent = new Intent(this, CaptureActivity.class);
  33.  
  34.             ts1.setContent(intent);
  35.  
  36.             TabSpec ts2 = mTabHost.newTabSpec("UseKeyboard");
  37.  
  38.             ts2.setIndicator("Use Keyboard");
  39.  
  40.             Intent intent2 = new Intent(this, ManualInputActivity.class);
  41.  
  42.             ts2.setContent(intent2);
  43.  
  44.             mTabHost.addTab(ts1);
  45.  
  46.             mTabHost.addTab(ts2);
  47.  
  48.  
  49.  
  50.         }
  51.  
  52.  
  53.  
  54.         public void onActivityResult(int requestCode, int resultCode, Intent intent) {
  55.  
  56.             if (requestCode == 0) {
  57.  
  58.                 if (resultCode == RESULT_OK) {
  59.  
  60.                     String barcode = intent.getStringExtra("SCAN_RESULT");
  61.  
  62.                     String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
  63.  
  64.                     // Handle successful scan
  65.  
  66.                 } else if (resultCode == RESULT_CANCELED) {
  67.  
  68.                     // Handle cancel
  69.  
  70.                 }
  71.  
  72.             }
  73.  
  74.         }
  75.  
  76.  
  77.  
  78. }
  79.  
  80.  
Parsed in 0.039 seconds, using GeSHi 1.0.8.4


and the second activity where the barcode can be entered manually:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. public final class ManualInputActivity extends Activity {
  3.  
  4.         @Override
  5.  
  6.         protected void onCreate(Bundle icicle) {
  7.  
  8.                 super.onCreate(icicle);
  9.  
  10.                 setContentView(R.layout.manual_input_tab);
  11.  
  12.  
  13.  
  14.                 Button goButton = (Button) findViewById(R.id.goButton);
  15.  
  16.                 goButton.setOnClickListener(mDoneListener);
  17.  
  18.                
  19.  
  20.             RadioButton rButton = (RadioButton) findViewById(R.id.RadioButton01);
  21.  
  22.             rButton.setChecked(true);
  23.  
  24.         }
  25.  
  26.  
  27.  
  28.         private final Button.OnClickListener mDoneListener = new Button.OnClickListener() {
  29.  
  30.                 public void onClick(View view) {
  31.  
  32.                         EditText editor = (EditText) findViewById(R.id.barcodeInputEditText);
  33.  
  34.                        
  35.  
  36.                         Intent result = new Intent(getIntent().getAction());
  37.  
  38.                         String barcode = editor.getText().toString();
  39.  
  40.                         result.putExtra("BARCODE", barcode);
  41.  
  42.                     setResult(RESULT_OK, result);
  43.  
  44.  
  45.  
  46.                         finish();
  47.  
  48.                 }
  49.  
  50.         };
  51.  
  52. }
  53.  
  54.  
Parsed in 0.034 seconds, using GeSHi 1.0.8.4


Thx for helping!
skel_
Once Poster
Once Poster
 
Posts: 1
Joined: Fri Nov 06, 2009 5:48 pm

Top

Postby DreamFlasher » Thu Jan 28, 2010 10:37 pm

Hi,
I am trying to do the same, and did not find a solution yet... what about you?
How did you integrate the ZXing barcode scanning into your app? For the moment I start it as an external activity, but I woul like to have it fully integrated, with visible tabs of my app.
Kind regards,
Marcel
DreamFlasher
Freshman
Freshman
 
Posts: 2
Joined: Sat Nov 07, 2009 7:48 pm
Location: Mannheim

Re: startActivityForResult in a Tab possible?

Postby CatalystDroid » Fri Mar 04, 2011 1:31 am

Hey ,

I am also working on developing an inventory tracking application for android uing the zxing barcode scanner integration. The problem I am currently having is providing the product information that zxing is able to display after a scan by querying google products. At least thats how I think that zxing gets the information. Any ideas on how I can implement this. I am able to scan the barcode and get the upc # but how can I then have it return product information from a query to a upc database or google product search? Any help, insight, ideas would be greatly appreciated. Thanks.
User avatar
CatalystDroid
Junior Developer
Junior Developer
 
Posts: 15
Joined: Wed Jan 12, 2011 3:36 am

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: Google [Bot] and 16 guests