title: understanding Android Services and threads
body: <p>I have doubts when it comes to Services. </p>
  
  <p>I know the service runs in the background, but I thought you necessarily needed to create a thread within the service, otherwise it would block the main thread and you would get an ANR error. </p>
  
  <p>I thought I got it! But then I read this in the Android Developer guide:</p>
  
  <blockquote>
    <p>…if your service performs intensive or blocking operations while the user interacts with an activity from the same application, the service will slow down activity performance. To avoid impacting application performance, you should start a new thread inside the service.></p>
  </blockquote>
  
  <p>The paragraph mentions "intensive or blocking operations", but doesn’t mention an ANR error, it mentions performance.  So how a service works?</p>
  
  <p>Supposing an Activity starts a Service. Does the Service run by default in the background of the main thread? Meaning that you can still use your activity while the service is running, but since your Activity and the Service are sharing the main thread’s resources, it would slow down the performance of your activity, and if Service is doing CPU intensive work, it could leave no resources for the activity to use, and eventually you would get an ANR error. </p>
  
  <p>The best practice (but not necessarily, if the service is doing light work) would be to start a new Thread within the Service, now the Activity and the Service are using their own thread’s resources. Then you could close your activity, but Android keeps the service thread alive.</p>
  
  <p>Is that it? Thanks =)</p>