MediaPlayer in separate Thread vs running in Service via startForeground()
<p>So, I'm streaming music in a separate thread. If I leave the app (<code>onPause()</code>, <code>onStop()</code> getting called, etc), the music continues to play, but eventually -- after opening other apps and switching between them and going back to the home screen -- my app is killed. No crash, just a <code>WIN DEATH</code> and <code>process com.myapp.android has died</code> in logcat. Obviously, it's legit for apps to be destroyed by the system in order to reclaim resources. </p>

<p>My question is: does running stuff in a thread off of the main (UI) thread mean that it now has less priority as far as the system is concerned? Meaning, is it more likely to be killed than if I run the media player in a <code>Service</code> and even use <code>startForeground()</code> to make the service run in the foreground? </p>

<p>Any thoughts or clarification would be greatly appreciated!</p>

<p><strong>EDIT</strong></p>

<p>Also, part of the documentation on Services confuses me. In pertinent part, it states: </p>

<blockquote>
  <p>Caution: A service runs in the main thread of its hosting process—the
  service does not   create its own thread and does not run in a
  separate process (unless you specify otherwise). This means that, if
  your service is going to do any CPU intensive work or blocking
  operations (such as MP3 playback or networking), you should create a
  new thread within the service to do that work.</p>
</blockquote>

<p>I've always ran MP3 playback in a service on the main thread and the UI remained responsive. If I'm supposed to put it in a separate thread as recommended in the above quotation, then won't I end up back where I started, namely with the media playback occuring off of the main thread, thereby increasing the likelihood that the playback is killed when other apps are opened, etc?</p>
