title: Detect 'home button pressed' event in android service displaying a UI (similar to facebook chatheads)
body: <p>In facebook chatheads, that are part of the facebook messenger app, I noticed the following behavior:
  As far as I can see, the chat head itself and the opened chat screen are all parts of a service. No activity is involved.</p>
  
  <p>How can I be sure?
  After I press home on the opened chat screen, it gets minimized back to a chat head, and I can immediately reopen the chat screen. If the chat screen was an activity, then reopening the activity via <code>startActivity(intent)</code> after the home button was pressed, would delay the start of the activity, as specified here:
  <a href="https://stackoverflow.com/questions/5600084/starting-an-activity-from-a-service-after-home-button-pressed-without-the-5-seco">Starting an activity from a service after HOME button pressed without the 5 seconds delay</a></p>
  
  <p>and here: <a href="https://stackoverflow.com/questions/8163399/reason-for-5-sec-delay-to-show-an-activity-on-pressing-the-home-button">Reason for 5 sec delay to show an activity on pressing the home button?</a></p>
  
  <p>in my service onCreate method, i use the following code to display a UI from service:</p>
  
  <pre><code>public class ServiceTest extends Service {
  ...
      @Override 
      public void onCreate() {
          super.onCreate();
  
          windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
  
          WindowManager.LayoutParams params = new WindowManager.LayoutParams(
              WindowManager.LayoutParams.WRAP_CONTENT,
              WindowManager.LayoutParams.WRAP_CONTENT,
              WindowManager.LayoutParams.TYPE_PHONE,
              WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
              PixelFormat.TRANSLUCENT);
  
          windowManager.addView(someView, params);
      }
  ....
  }
  </code></pre>
  
  <p>Does anyone have an idea how can I receive the 'home button pressed' event directly from a service displaying a UI? I would like to minimize my view (similar to facebook chat heads) when the user presses the home button.</p>