title: Long running Android service is getting recreated over and over
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/10506346/my-android-service-is-stopping-abruptly-and-a-new-one-created">My Android service is stopping abruptly and a new one created</a>  </p>
  </blockquote>
  
  
  
  <p>I have a simple Android Activity with one button to start and stop a long running Android Service (which does some simple logging). As soon as I start the service, I close the app (Activity) and the service should then run in the background indefinitely.</p>
  
  <p>But it doesn't. At random times, the Application object this Service belongs to is recreated by the OS and then my Service is as well. So it's not just that the Service is getting onStartCommand called, but first it gets onCreate called, creating a new Service. I don't know what happens to the old one, it just goes away - onDestroy is not called or anything.</p>
  
  <p>I run the Service as START_STICKY, I am not using the main UI thread in any way, so there should be no issues there. I just can't understand what the problem is.</p>
  
  <p>The Service is running fine, then boom, my Application gets an onCreate, my Service gets an onCreate and onStartCommand and the old Service, which was in the middle of logging goes, away without any notice or warning. The new Service starts logging. I end up with a bunch of disconnected logs where there should be just one.</p>