title: Android Window Manager block system back key
body: <p>I have an floating view like Facebook chat buble, but unlike it, my overlay has a EditText and need to be focusable.</p>
  
  <p>Here is my floating view code</p>
  
  <pre><code>        //Inflate the floating view layout we created
          mFloatingView = LayoutInflater.from(this).inflate(R.layout.floating_widget_layout, null);
  
          //Add the view to the window.
          final WindowManager.LayoutParams params = new WindowManager.LayoutParams(
                  WindowManager.LayoutParams.WRAP_CONTENT,
                  WindowManager.LayoutParams.WRAP_CONTENT,
                  WindowManager.LayoutParams.TYPE_PHONE,
                  WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,
                  PixelFormat.TRANSLUCENT);
  
          //Specify the view position
          params.gravity = Gravity.TOP | Gravity.START;        //Initially view will be added to top-left corner
          params.x = 0;
          params.y = 100;
  
          //Add the view to the window
          mWindowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
          mWindowManager.addView(mFloatingView, params);
  </code></pre>
  
  <p>It is almost okey but there is a problem. When I create overlay from <strong>service</strong>, System Back Button not working. If I use <code>FLAG_NOT_FOCUSABLE</code> System buttons; home, recents and back works as expected. I made some research at SO and find out that it is a security issue so I started to find alternative solutions and found <a href="https://stackoverflow.com/questions/12927682/add-view-by-using-windowmanager-but-can-back-key-press">this</a> then changed my code</p>
  
  <pre><code>// Wrapper for intercepting System/Hardware key events
  ViewGroup wrapper = new FrameLayout(this) {
      @Override
      public boolean dispatchKeyEvent(KeyEvent event) {
          if (event.getKeyCode()==KeyEvent.KEYCODE_BACK) {
              Log.v("Back", "Back Key");
              return true;
          }
          return super.dispatchKeyEvent(event);
      }
  };
  
  //Inflate the floating view layout we created
  mFloatingView = LayoutInflater.from(this).inflate(R.layout.floating_widget_layout, wrapper);
  
  //Add the view to the window.
  final WindowManager.LayoutParams params = new WindowManager.LayoutParams(
          WindowManager.LayoutParams.WRAP_CONTENT,
          WindowManager.LayoutParams.WRAP_CONTENT,
          WindowManager.LayoutParams.TYPE_PHONE,
          WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,
          PixelFormat.TRANSLUCENT);
  
  //Specify the view position
  params.gravity = Gravity.TOP | Gravity.START;        //Initially view will be added to top-left corner
  params.x = 0;
  params.y = 100;
  
  //Add the view to the window
  mWindowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
  mWindowManager.addView(mFloatingView, params);
  </code></pre>
  
  <p>Now I can get back press from my floating view but how can I pass this event(back press) to the foreground app(other app, not mine) ? I found <a href="https://stackoverflow.com/questions/27370216/android-how-can-a-service-app-dispatch-keyevents-to-another-foreground-app">this</a> but it didn't help me</p>
  
  <p>If someone can help me or at least give a clue, I will be appreciate</p>
  
  <p><strong>Summary</strong> </p>
  
  <p>I have an overlay view, it needs to be focusable, but back press button not working when it is focusable how I can solve this?</p>