title: Check application is minimized/background
body: <p>I am so surprised!</p>
  
  <p>Because not able identify application currently in foreground or background,</p>
  
  <p>when i pressed home button and my application is not in foreground. then after i have used to check application running in foreground or not.</p>
  
  <pre><code>public boolean isAppOnForeground()
      {
  
          ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
          List&lt;RunningAppProcessInfo&gt; appProcesses = activityManager.getRunningAppProcesses();
          if (appProcesses == null) { return false; }
          final String packageName = context.getPackageName();
          for (RunningAppProcessInfo appProcess : appProcesses)
          {
              if (appProcess.importance == RunningAppProcessInfo.IMPORTANCE_FOREGROUND &amp;&amp; appProcess.processName.equals(packageName)) { return true; }
          }
          return false;
  
      }
  </code></pre>
  
  <p>it will returns always <strong>true</strong> even if my application actually not in foreground. </p>
  
  <p><strong>Note:</strong>
  My application have 2 services,
  1 service will be canceled when application is removed from recent task list( <strong>that i have achieved.</strong>)
  2 service will be canceled when application goes in background. (that is check wifi signal strength.)</p>
  
  <p><strong>how to know app is foreground or background?</strong> </p>
  
  <p><strong>how to stop service when application is not in foreground?</strong></p>