The history preference is now loaded at construction time
diff --git a/android/src/com/google/zxing/client/android/CaptureActivity.java b/android/src/com/google/zxing/client/android/CaptureActivity.java
index 26b0c88..d4fe7db 100755
--- a/android/src/com/google/zxing/client/android/CaptureActivity.java
+++ b/android/src/com/google/zxing/client/android/CaptureActivity.java
@@ -136,8 +136,6 @@
setContentView(R.layout.capture);
hasSurface = false;
- historyManager = new HistoryManager(this);
- historyManager.trimHistory();
inactivityTimer = new InactivityTimer(this);
beepManager = new BeepManager(this);
ambientLightManager = new AmbientLightManager(this);
@@ -148,6 +146,10 @@
@Override
protected void onResume() {
super.onResume();
+
+ // historyManager must be initialized here to update the history preference
+ historyManager = new HistoryManager(this);
+ historyManager.trimHistory();
// CameraManager must be initialized here, not in onCreate(). This is necessary because we don't
// want to open the camera driver and measure the screen size if we're going to show the help on
@@ -292,6 +294,7 @@
ambientLightManager.stop();
beepManager.close();
cameraManager.closeDriver();
+ historyManager = null;
if (!hasSurface) {
SurfaceView surfaceView = (SurfaceView) findViewById(R.id.preview_view);
SurfaceHolder surfaceHolder = surfaceView.getHolder();
@@ -433,10 +436,7 @@
boolean fromLiveScan = barcode != null;
if (fromLiveScan) {
- SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
- boolean shouldSaveScan = prefs.getBoolean(PreferencesActivity.KEY_ENABLE_HISTORY, true);
- if(shouldSaveScan)
- historyManager.addHistoryItem(rawResult, resultHandler);
+ historyManager.addHistoryItem(rawResult, resultHandler);
// Then not from history, so beep/vibrate and we have an image to draw on
beepManager.playBeepSoundAndVibrate();
drawResultPoints(barcode, scaleFactor, rawResult);
diff --git a/android/src/com/google/zxing/client/android/history/HistoryManager.java b/android/src/com/google/zxing/client/android/history/HistoryManager.java
index 04956f2..08cdaec 100644
--- a/android/src/com/google/zxing/client/android/history/HistoryManager.java
+++ b/android/src/com/google/zxing/client/android/history/HistoryManager.java
@@ -69,9 +69,12 @@
private static final String[] ID_DETAIL_COL_PROJECTION = { DBHelper.ID_COL, DBHelper.DETAILS_COL };
private final Activity activity;
+ private final boolean enableHistory;
public HistoryManager(Activity activity) {
this.activity = activity;
+ SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(activity);
+ enableHistory = prefs.getBoolean(PreferencesActivity.KEY_ENABLE_HISTORY, true);
}
public boolean hasHistoryItems() {
@@ -152,7 +155,7 @@
// Do not save this item to the history if the preference is turned off, or the contents are
// considered secure.
if (!activity.getIntent().getBooleanExtra(Intents.Scan.SAVE_HISTORY, true) ||
- handler.areContentsSecure()) {
+ handler.areContentsSecure() || !enableHistory) {
return;
}