check if there are 2 instances running
<p>I am trying to check if my app is running already if the user is trying to enter it again.
it is possible if one app Launched   anther one and the user entering with a mobile to the second one, and will be 2 instance.</p>

<p>my launcher app that starts the original one  looks like that :</p>

<pre><code>  Intent i = new Intent(Intent.ACTION_MAIN);
  PackageManager manager = getPackageManager();

  i = manager.getLaunchIntentForPackage("com.test.vayo");
  i.addCategory(Intent.CATEGORY_LAUNCHER);
   startActivity(i);
</code></pre>

<p>On my original code I am trying to check if there is 2 instance but always get true on this code</p>

<pre><code>    if (processName == null) {
        return false;
    }
    ActivityManager manager = (ActivityManager) context.getSystemService(context.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>the proccessName taken from this code, the pid is from android.os.Process.myPid():</p>

<pre><code>private String getAppName(int pID)
</code></pre>

<p>{</p>

<pre><code>String processName = "";
ActivityManager am = (ActivityManager)context.getSystemService(context.ACTIVITY_SERVICE);

List l = am.getRunningAppProcesses();
Iterator i = l.iterator();
PackageManager pm = context.getPackageManager();
while(i.hasNext()) 
{
      ActivityManager.RunningAppProcessInfo info = (ActivityManager.RunningAppProcessInfo)(i.next());
      try 
      { 
          if(info.pid == pID)
          {
              CharSequence c = pm.getApplicationLabel(pm.getApplicationInfo(info.processName, PackageManager.GET_META_DATA));
              //Log.d("Process", "Id: "+ info.pid +" ProcessName: "+ info.processName +"  Label: "+c.toString());
              //processName = c.toString();
              processName = info.processName;
          }
      }
      catch(Exception e) 
      {
            //Log.d("Process", "Error&gt;&gt; :"+ e.toString());
      }
 }
   return processName;
 }
</code></pre>

<p>hope you can tell whats wrong why I am getting always true on my first block of code.
thanks a lot!!</p>
