title: ActivityManager unable to restart Service after killed
body: <p>i have the following onCreate() on the MainActivity:</p>
  
  <pre><code>public void onCreate(Bundle savedInstanceState) {
      Intent intent = new Intent(this, BackgroundService.class);
      getApplicationContext().startService(intent);
  }
  </code></pre>
  
  <p>and this Service:</p>
  
  <pre><code>public class BackgroundService extends Service {
  
      private Looper mServiceLooper;
      private ServiceHandler mServiceHandler;
  
      public BackgroundService() {}
  
      @Override
      public void onCreate() {
          HandlerThread thread = new HandlerThread("ServiceStartArguments");
          thread.start();
          mServiceLooper = thread.getLooper();
          mServiceHandler = new ServiceHandler(mServiceLooper);
      }
  
      private final class ServiceHandler extends Handler {
  
          public ServiceHandler(Looper looper) {
              super(looper);
          }
  
          @Override
          public void handleMessage(Message msg) {
              try {
  
                  while(true) {
                      Log.d("BackgroundService", "Hi! I'm working...");
                      Thread.sleep(10000);
                  }
  
              } catch (Exception e) {
                  Thread.currentThread().interrupt();
              }
  
              stopSelf(msg.arg1);
          }
      }
  
  
      @Override
      public int onStartCommand(Intent intent, int flags, int startId) {
  
          Message msg = mServiceHandler.obtainMessage();
          msg.arg1 = startId;
          mServiceHandler.sendMessage(msg);
  
          return START_STICKY;
  
      }
  
      @Override
      public IBinder onBind(Intent intent) {
          return null;
      }
  
  }
  </code></pre>
  
  <p>When, form the Android task manager i kill only the BackgroundService (from "In Use" tab), or from the "recent app" i swipe out my application, the the service just restart, and this is ok.</p>
  
  <p>But.. when from the tab "All Apps" i kill the App itself the service does not restart properly.</p>
  
  <p>Using Logcat via ADB i can see the following logs:</p>
  
  <pre><code>I/ActivityManager(  557): Force stopping io.fornace.giarvis appid=10185 user=0: from pid 21521
  I/ActivityManager(  557): Killing 31260:io.fornace.giarvis/u0a185 (adj 9): stop io.fornace.giarvis
  D/ConnectivityService(  557): ConnectivityService NetworkRequestInfo binderDied(NetworkRequest [ id=301, legacyType=-1, [ Capabilities: INTERNET&amp;NOT_RESTRICTED&amp;TRUSTED] ], android.os.BinderProxy@c24d6f5)
  I/WindowState(  557): WIN DEATH: Window{1b01ccf2 u0 io.fornace.giarvis/io.fornace.giarvis.MainActivity}
  D/ConnectivityService(  557): releasing NetworkRequest NetworkRequest [ id=301, legacyType=-1, [ Capabilities: INTERNET&amp;NOT_RESTRICTED&amp;TRUSTED] ]
  E/ConnectivityService(  557): RemoteException caught trying to send a callback msg for NetworkRequest [ id=301, legacyType=-1, [ Capabilities: INTERNET&amp;NOT_RESTRICTED&amp;TRUSTED] ]
  W/ActivityManager(  557): Scheduling restart of crashed service io.fornace.giarvis/.BackgroundService in 1000ms
  I/ActivityManager(  557):   Force finishing activity 3 ActivityRecord{adf055c u0 io.fornace.giarvis/.MainActivity t281}
  I/ActivityManager(  557):   Force stopping service ServiceRecord{3a1c7d8c u0 io.fornace.giarvis/.BackgroundService}
  W/ActivityManager(  557): Spurious death for ProcessRecord{1bac5c8a 31260:io.fornace.giarvis/u0a185}, curProc for 31260: null
  </code></pre>
  
  <p>I can't understand why after the</p>
  
  <blockquote>
    <p>Scheduling restart of crashed service</p>
  </blockquote>
  
  <p>there are these two lines:</p>
  
  <blockquote>
    <p>Force finishing activity 
    Force stopping service</p>
  </blockquote>
  
  <p>This is the manifest part about the service:</p>
  
  <pre><code>&lt;service
     android:name=".BackgroundService"
     android:enabled="true"
     android:exported="true"
     android:stopWithTask="false"&gt;
  &lt;/service&gt;
  </code></pre>