I have 2 different Layouts
One is a TabHost which hosts different tabs where one is a QR Scanner Tab. If I click the Button the it starts the scanning App and Scans it and returns it to the activity and shows the result (I start it with StartActivityForResult()…).
The other Layout is a ListView where you can select between the functions. If you select QR Scanner there it opens up the Activity. If you click Scan QR Code there it starts ZXing again but if something has been scanned it falls back to the Listview Layout.
This is how my activities are declared in the manifest (ListView Layout):
<activity
android:name=".ListActivities"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="@string/app_name" >
</activity>
And the TabHost:
<activity
android:name=".TabHoster"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="@string/app_name" >
</activity>
And this is the Manifest entry of the ScanQR class:
<activity
android:name=".QRScanner"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="@string/app_name"
android:launchMode="singleInstance" />
Here is the code from ListActivities -> ScanQR:
Intent intent = new Intent(this, ScanQR.class);
startActivity(intent);
And this is the code to launch the ZXing library:
Intent intent = new Intent("com.google.zxing.client.android.SCAN");
intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
startActivityForResult(intent, 0);
And the Code for the result returned from it:
if (resultCode == RESULT_OK) {
String contents = intent.getStringExtra("SCAN_RESULT");
txtPleaseScan.setVisibility(View.GONE);
ScrollView qrLayout = (ScrollView) findViewById(R.id.qrLayout);
qrLayout.setVisibility(View.VISIBLE);
txtQRResult.setText(contents);
} else if (resultCode == RESULT_CANCELED) {
}
btw I’m using the same ScanQR code for both layouts…
Wow ok I was able to fix it myself… The problem was in the
AndroidManifest.xml…The
android:launchModeand theandroid:configChangeswere wrong there I guess… After removing it, it works fine in both layouts…