title: How to tell if notification shade is pulled down in android
body: <p>I have a program that creates a notification if the application is not running. To do this, I have used the following code:</p>
  
  <pre><code>public void onWindowFocusChanged(boolean focus)
  {
      inFocus = focus;
  
      if (inFocus)
      {//If this activity is in focus, fills data and clears notifications
          fillData();
          Notify.clear();
      }
      else
      {
          if (!RespondScreen.inFocus &amp;&amp; !ClearDialog.inFocus)
          {
              Creates a notification
          }
      }
  }
  </code></pre>
  
  <p>This works fine, except when the notification shade is pulled down. This causes the activity to not be in focus, and because neither of the other two activities are in focus, a notification is created. This notification is destroyed as soon as the shade is pulled back up, but it creates an annoying, unnecessary disturbance to the user. Is there some setting I can use to test if the notification shade is in focus, or another way entirely?</p>
  
  <p><strong>Edit: Using Qberticus' advice, I was able to find a workable solution:</strong></p>
  
  <pre><code>    public void onWindowFocusChanged(boolean focus)
  {
      if (focus)
      {//If this activity is in focus, fills data and clears notifications
          inFocus = focus;
          fillData();
          Notify.clear();
      }
  }
  
  @Override
  public void onPause()
  {
      super.onPause();
      inFocus = false;
      Handler handler = new Handler();  
      handler.postDelayed(new Runnable() {  
           public void run() {  
               if (!RespondScreen.inFocus &amp;&amp; !ClearDialog.inFocus)
               {
                  Intent notifier = new Intent();
                  notifier.setAction("itp.uts.program.NOTIFY");
                  Bundle bundle = new Bundle();
                  bundle.putBoolean("StartNotify", true);
                  bundle.putBoolean("StartSound", false);
                  notifier.putExtras(bundle);
                  getApplicationContext().startService(new Intent(notifier));
               }
           }  
      }, 200);   
  }
  </code></pre>
  
  <p>The onResume method was for some reason not working with Notify.clear(), so I used a combination of my attempt and Qberticus' suggestion. It's a little clumsy, but it works perfectly.</p>