title: How to show a message to the user if camera is already in-use by another application
body: <pre><code>public void onResume() {
      super.onResume();
      boolean error = false;
      try {
      Camera = Camera.open(1);
    } catch (RuntimeException ex) {
      error = true;
      ex.printStackTrace();
  }
  </code></pre>
  
  <p>changed code here.</p>
  
  <p>To show the alert dialog message if camera is already opened in other application.</p>
  
  <pre><code>if(error){
          new AlertDialog.Builder(this)
                  .setMessage("Camera in use ")
                  .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                      @Override
                      public void onClick(DialogInterface dialog, int which) {
  
                  finish();
              }
          })
          .setIcon(android.R.drawable.ic_dialog_alert)
          .show();
  
      }
  </code></pre>
  
  <p>used finish() here, just to avoid crash of the application.</p>
  
  <pre><code>    finish();
  
       if (mCamera != null) {
              mCamera.startPreview();
             mPreview.setCamera(mCamera);
  
         }
      }
  
  
  
   public void finish() {
          ViewGroup view = (ViewGroup) getWindow().getDecorView();
          view.removeAllViews();
          super.finish();
      }
  </code></pre>
  
  <p>It is entering the if condition, but it not showing alert dialog. Instead it crashes the application. But when I use finish() after the if statement is closed. It just closes the application without crashing. </p>
  
  <p>E/WindowManager﹕ android.view.WindowLeaked I'm getting this error when application closed. </p>
  
  <p>How to avoid this error and show the user a dialog box. </p>