title: Android how to clearing touch events between activitie and dialog
body: <p>Scenario:</p>
  
  <p>There is an activity and a dialog.The Activity has a button to launch that shows the Dialog on screen.</p>
  
  <p>Problem:</p>
  
  <p>when Dialog the is showing and I touch the button (instead of single tap), Dialog becomes invisible but quickly shows up again ! I want to touch outside of the dialog but do not show The dialog again.</p>
  
  <p>How can this be done? Or is there another fix ?</p>
  
  <p>here is my Activity</p>
  
  <pre><code>public class MyAndroidAppActivity extends Activity {
  
  Button button;
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
  
      button = (Button) findViewById(R.id.button1);
  
      button.setOnClickListener(new OnClickListener() {
  
          @Override
          public void onClick(View arg0) {
  
             CallDialog call = new CallDialog();
             call.show(this);
  
          }
  
      });
  
   }
  </code></pre>
  
  <p>}</p>
  
  <p>And my Dialog</p>
  
  <pre><code>public class CallDialog{
  
  Dialog mDialog;
  
  public void show(Context context){
  
   Dialog mDoialog = new Dialog(context);
   setContentView(R.layout.dialog);
  
  Window window = this.getWindow();
  window.setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,
  WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
  
  window.setFlags(WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH,
  WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH);
  
  getWindow().getDecorView().getRootView().setOnTouchListener(new OnTouchListener(){
      @Override
      public boolean onTouch(View v, MotionEvent event) {
  
      if(event.getAction() == MotionEvent.ACTION_OUTSIDE){  
  
      mDialog.dismiss();
  
      }
  
      return false;
     }           
  });
  </code></pre>
  
  <p>}
     }</p>