problem when starting the scan process (CaptureActivity) from another actvity

57 views
Skip to first unread message

rprdev

unread,
Sep 6, 2011, 11:26:23 AM9/6/11
to zxing
hi everybody.

i created a project from the zxing /android sources. everything worked
fine.

then..i wanted to call the scanning process from another activity und
get the result back to that activity. the problem is: my own activity
starts the scanner..the scanner scans the barcode..i get the result
back to my activity und i display it. it works! but then..when i´m in
my own activity..see the result..and i change the orientation..the
capture view from the zxing scanner comes back in foreground and my
activity is gone.
also..if i hear the beep sound (barcode = scanned)..and then i move
the phone..my activity is called but not displayed because the capture
view is "faster called" again because i moved the phone.

my own activity is as simple as it can be and looks like this:

public class BarcodeAct extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

Intent intent = new Intent(this, CaptureActivity.class);
intent.putExtra("SCAN_MODE", "PRODUCT_MODE");
startActivityForResult(intent, 0);
}

@Override
protected void onActivityResult(int requestCode, int resultCode,
Intent data) {
//display result
}
}

I made no changes to the CaptureActivity class except for the
onResume() method. i changed the orignal sources from:

....
....
Intent intent = getIntent();
String action = intent == null ? null : intent.getAction();
String dataString = intent == null ? null :
intent.getDataString();
if (intent != null && action != null) {
if (action.equals(Intents.Scan.ACTION)) {
// Scan the formats the intent requested, and return the
result to the calling activity.
source = Source.NATIVE_APP_INTENT;
decodeFormats =
DecodeFormatManager.parseDecodeFormats(intent);
if (intent.hasExtra(Intents.Scan.WIDTH) &&
intent.hasExtra(Intents.Scan.HEIGHT)) {
int width = intent.getIntExtra(Intents.Scan.WIDTH, 0);
int height = intent.getIntExtra(Intents.Scan.HEIGHT, 0);
if (width > 0 && height > 0) {
CameraManager.get().setManualFramingRect(width, height);
}
}
} else if (dataString != null &&
dataString.contains(PRODUCT_SEARCH_URL_PREFIX) &&
dataString.contains(PRODUCT_SEARCH_URL_SUFFIX)) {
// Scan only products and send the result to mobile Product
Search.
source = Source.PRODUCT_SEARCH_LINK;
sourceUrl = dataString;
decodeFormats = DecodeFormatManager.PRODUCT_FORMATS;
} else if (dataString != null &&
dataString.startsWith(ZXING_URL)) {
// Scan formats requested in query string (all formats if none
specified).
// If a return URL is specified, send the results there.
Otherwise, handle it ourselves.
source = Source.ZXING_LINK;
sourceUrl = dataString;
Uri inputUri = Uri.parse(sourceUrl);
returnUrlTemplate =
inputUri.getQueryParameter(RETURN_URL_PARAM);
decodeFormats =
DecodeFormatManager.parseDecodeFormats(inputUri);
} else {
// Scan all formats and handle the results ourselves (launched
from Home).
source = Source.NONE;
decodeFormats = null;
}
characterSet =
intent.getStringExtra(Intents.Scan.CHARACTER_SET);
} else {
source = Source.NONE;
decodeFormats = null;
characterSet = null;
}
....
....


to

....
....
Intent intent = getIntent();
source = Source.NATIVE_APP_INTENT;
decodeFormats = DecodeFormatManager.parseDecodeFormats(intent);
...
...

these are the lines from the first if condition..if the activity was
called from another app (scanning via intent: new
Intent("com.google.zxing.client.android.SCAN");").

of course..i also changed the manifest file. so that my activity is
launched at start.

i dont get it. there is some thread that always calls the
CaptureActivity even if it got finish()'ed. i made no changes to the
sources. its the same code like i would call it via android.SCAN. and
via that method there is not such a bug that the capture view comes
back again...
the only difference is that i call the scanner wihtin the same
application.

hope anybody has an idea :(

thanks in advance


Sean Owen

unread,
Sep 6, 2011, 11:29:11 AM9/6/11
to zx...@googlegroups.com
Please don't copy our code so directly. You should be writing your own application; much of the code and design choices will not be appropriate for you anyway.
You've made changes to it and it's broken, so the issue is in your changes. I don't think we can help you with your code.

rprdev

unread,
Sep 6, 2011, 11:50:40 AM9/6/11
to zxing
thats what i want to do. but first i want to understand relevant code
and im just playing around. i made no changes to the code that would
cause this behaviour. this is a problem when calling the scanning
process inside the same app from another activity instead of calling
it from anoher app via com.google.zxing.client.android.SCAN
Reply all
Reply to author
Forward
0 new messages