title: Music service stops when the activity is stopped/closed?
body: <p>I've created a music service for my application (a music player), and after making some tests I'm observing a behaviour that's causing me a headache as I don't know how to solve it.</p>
  
  <p>For testing purposes, I've modified the service so, as soon as it's started, it plays a specific mp3 file from my sd card. Also, I've modified the application so the first activity is started, it starts the service, and then it calls "finish()".</p>
  
  <p>Ok, so... I launch the application, and the first activity starts, my service starts and plays the music, the activity finishes and the application is closed and... the music is stopped and after some seconds the service is restarted (I'm using the START_STICKY flag, so I suppose that's normal).</p>
  
  <p>I don't want the music to be stopped when I close the application, or in another words, I don't want the service to be stopped (and then restarted because it's been stopped) when my application is closed.</p>
  
  <p>Right now, to control the music service, I start the service and then I bind to it so I can call the service functions I've defined in an interface.</p>
  
  <p>Any ideas?</p>
  
  <p>Thanks!</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>This is an example of what my application and service do (in the tests I'm doing).</p>
  
  <p>Activity:</p>
  
  <pre><code>public class FirstActivity extends SherlockFragmentActivity {
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
  
          startService(new Intent(this, MyService.class));
  
          ...
          // Here is a postDelayed that will run after 2 seconds and call finish()
      }
  }
  </code></pre>
  
  <p>Service:</p>
  
  <pre><code>public class MyService extends Service {
      private MediaPlayer mPlayer;
  
      @Override
      public void onCreate() {
          mPlayer = new MusicPlayer(this);
      }
  
      @Override
      public int onStartCommand(Intent intent, int flags, int startId) {
          // Here is the code that plays the music using MediaPlayer
  
          return START_STICKY;
      }
  }
  </code></pre>