title: How to check whether a particular app is running or not in Android
body: <p>I am developing an app which requires to check if a particular app is running. I am using the following code but it always tells me using Toast message that the app which by the way is running is not.</p>
  
  <p>Code for the function being used:</p>
  
  <pre><code>boolean isNamedProcessRunning(String processName){
    if (processName == null) 
     return false;
  
    ActivityManager manager = 
       (ActivityManager) this.getSystemService(ACTIVITY_SERVICE);
    List&lt;RunningAppProcessInfo&gt; processes = manager.getRunningAppProcesses();
    for (RunningAppProcessInfo process : processes)
    {
       if (processName.equals(process.processName))
       {
           return true;
       }
    }
    return false;
   }
  </code></pre>
  
  <p>Function call:</p>
  
  <pre><code>if(isNamedProcessRunning("WhatsApp")){
      Toast.makeText(this.getBaseContext(),"WhatsApp running", Toast.LENGTH_SHORT).show();
  }
  else{
      Toast.makeText(this.getBaseContext(),"WhatsApp Not running", Toast.LENGTH_SHORT).show();
  
  }
  </code></pre>