@Override
 public void onDestroy() {
   super.onDestroy();
   if (mProgressDialog != null) {
     mProgressDialog.dismiss();
   }
 }
  @Override
  public void onStop() {
    super.onStop();

    // if activity is closed suddenly,
    // dismiss the progress dialog.
    if (mProgressDialog != null) {
      mProgressDialog.dismiss();
    }
  }
  @Override
  public void takePicture() {
    mTakePictureBtn.setEnabled(false);
    mProgressDialog.show();

    PictureTransaction pictureTransaction = new PictureTransaction(getHost());
    pictureTransaction.needBitmap(true);
    pictureTransaction.flashMode(flashMode);
    super.takePicture(pictureTransaction);
  }
  @Override
  public void onCreate(Bundle state) {
    super.onCreate(state);
    setRetainInstance(true);

    SimpleCameraHost.Builder builder =
        new SimpleCameraHost.Builder(new DemoCameraHost(getActivity()));
    setHost(builder.useFullBleedPreview(true).build());

    mProgressDialog = new ProgressDialog(getActivity());
    mProgressDialog.setMessage(getString(R.string.progress_title));
    mProgressDialog.setIndeterminate(true);
    mProgressDialog.setCancelable(false);
  }