title: Android - What happens to a bound service if the binding activity was killed?
body: <p>Android provides the Service class, which can be useful for background or non-UI operations.</p>
  
  <p>I have a question about Services' lifecycle.</p>
  
  <p>I know that bound services have the lifecycle like following:</p>
  
  <ol>
  <li>Some component starts the Service via bindService() -> onCreate()</li>
  <li>onBind()</li>
  <li>process</li>
  <li>The binding component calls unbindService() -> onUnbind()</li>
  <li>onDestroy()</li>
  </ol>
  
  <p>My question is:</p>
  
  <p>Activities usually call unbindService() at onStop().
  However, the Activity can be killed without calling onStop() - I mean, when the system memory is low, the only method that must be called is onPause(). onStop() is after onPause(). Before calling onStop(), the Activity can be destroyed.</p>
  
  <p>In this case, the Service didn't get unbindService(), so the Service is still running. Is this right?</p>
  
  <p>Of course, this rarely happens because Services are background by default. (Services are more likely to be killed by system on low memory.) However, a "Foreground" Service has higher priority than the "onPause()ed activity." according to <a href="http://developer.android.com/guide/components/processes-and-threads.html" rel="noreferrer">http://developer.android.com/guide/components/processes-and-threads.html</a> . In this case, the binding activity will be killed first.</p>
  
  <p>If this thing happens, the Service does not end? If memory is not low anymore, then the Activity will be created again, but will call bindService() again since it is a new instance. Also, the Activity even may not restart. Isn't this right? What can I do in this case?</p>