@Override
 protected void onDestroy() {
   inactivityTimer.shutdown();
   super.onDestroy();
   offLight();
   OttoAppConfig.getInstance().unregister(this);
 }
  @Override
  protected void onResume() {
    super.onResume();

    // 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
    // first launch. That led to bugs where the scanning rectangle was the
    // wrong size and partially
    // off screen.
    cameraManager = new CameraManager(getApplication());

    handler = null;

    if (isHasSurface) {
      // The activity was paused but not stopped, so the surface still
      // exists. Therefore
      // surfaceCreated() won't be called, so init the camera here.
      initCamera(scanPreview.getHolder());
    } else {
      // Install the callback and wait for surfaceCreated() to init the
      // camera.
      scanPreview.getHolder().addCallback(this);
    }

    inactivityTimer.onResume();
  }
  /**
   * A valid barcode has been found, so give an indication of success and show the results.
   *
   * @param rawResult The contents of the barcode.
   * @param bundle The extras
   */
  public void handleDecode(Result rawResult, Bundle bundle) {
    inactivityTimer.onActivity();

    if (rawResult == null) {
      Snackbar.make(scanContainer, getString(R.string.decode_null), Snackbar.LENGTH_SHORT).show();
      return;
    }

    //        beepManager.playBeepSoundAndVibrate();
    AudioPlayer.getInstance(this).playRaw(R.raw.scan, false, false);
    //        MyUtil.vibrate(this);

    operateResult(rawResult);
  }
 @Override
 protected void onPause() {
   if (handler != null) {
     handler.quitSynchronously();
     handler = null;
   }
   inactivityTimer.onPause();
   beepManager.close();
   cameraManager.closeDriver();
   if (!isHasSurface) {
     scanPreview.getHolder().removeCallback(this);
   }
   super.onPause();
 }