title: How to kill an Android app background process?
body: <p>I have an app with two processes. The second process starts when an Activity is created. Find below an excerpt of that Activity in the Manifest:</p>
  
  <pre><code>    &lt;activity
          android:name=".ActivityInAnotherProcess"
          android:process=":anotherprocess"
          android:launchMode="singleTask"
          ...
  </code></pre>
  
  <p>After the ":anotherprocess" starts I need to kill the main process somehow, through the adb, in code, however.</p>
  
  <p>I've tried "Terminate Application" in the DDMS and the main process is killed but recreated after a few seconds.</p>
  
  <p>I've tried this code:</p>
  
  <pre><code>String packageName = c.getPackageName();
  ActivityManager activityManager = (ActivityManager) c.getSystemService(Context.ACTIVITY_SERVICE);
  activityManager.killBackgroundProcesses(packageName);
  </code></pre>
  
  <p>but the main process is killed only to be recreated after a few seconds.</p>
  
  <p><strong>UPDATE:</strong>
  The code posted above works. I was calling it a few seconds after starting the Activity in the other process but it seems the other process was not fully started before I killed the main process. Now I'm killing the main process from the other process. This works now. Thanks all!</p>