私は2つの異なるレイアウトを持っています
1 つは、QR スキャナー タブであるさまざまなタブをホストする TabHost です。ボタンをクリックすると、スキャンアプリが起動し、スキャンしてアクティビティに戻り、結果が表示されます(StartActivityForResult()...で開始します)。もう 1 つのレイアウトは、機能を選択できる ListView です。そこで QR スキャナーを選択すると、アクティビティが開きます。そこで QR コードのスキャンをクリックすると、ZXing が再び開始されますが、何かがスキャンされた場合はリストビュー レイアウトに戻ります。
これは、マニフェスト (ListView レイアウト) でアクティビティを宣言する方法です。
<activity
android:name=".ListActivities"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="@string/app_name" >
</activity>
そしてタブホスト:
<activity
android:name=".TabHoster"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="@string/app_name" >
</activity>
そして、これは ScanQR クラスのマニフェスト エントリです。
<activity
android:name=".QRScanner"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="@string/app_name"
android:launchMode="singleInstance" />
ListActivities -> ScanQR からのコードは次のとおりです。
Intent intent = new Intent(this, ScanQR.class);
startActivity(intent);
これは、ZXing ライブラリを起動するコードです。
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);
そして、それから返された結果のコード:
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) {
}
ところで、両方のレイアウトに同じ ScanQR コードを使用しています...