title: How to stop multiple android services in a List of services that use MediaPlayer to play many songs simultaneously?
body: <p>Hey guys sorry if this has been asked before but I have been reading other answers and documentation for more than 3 hours with no success, I really can't find how to solve this problem.</p>
  
  <h2>Description</h2>
  
  <p>So I have this List:</p>
  
  <p><code>private List&lt;MusicService&gt; songList;</code></p>
  
  <p>And adding to it all my needed services:</p>
  
  <pre><code>private Intent rainIntent;
  private Intent stormIntent;
  private Intent oceanIntent;
  </code></pre>
  
  <p>Then I initialize them: </p>
  
  <pre><code>    rainIntent = new Intent(this, MusicService.class);
      stormIntent = new Intent(this, MusicService.class);
      oceanIntent = new Intent(this, MusicService.class);
  </code></pre>
  
  <p>Then I pass them the ID of songs I want to play <code>onStartCommand()</code></p>
  
  <pre><code>    rainIntent.putExtra(MusicService.SONG_ID, R.raw.rain);
      songsIntentsList.add(rainIntent);
      stormIntent.putExtra(MusicService.SONG_ID, R.raw.thunder);
      songsIntentsList.add(stormIntent);
      oceanIntent.putExtra(MusicService.SONG_ID, R.raw.ocean);
      songsIntentsList.add(oceanIntent);
  </code></pre>
  
  <p>When I use the list to start all services there's no problem, this works fine:</p>
  
  <pre><code>private void startSongsServices() {
  
      for (Intent intent : songsIntentsList) {
          context.startService(intent);
      }
  
  }
  </code></pre>
  
  <h1>My problem:</h1>
  
  <p>But when trying to use stopService() it doesn't work what can I do? Just like the following:</p>
  
  <pre><code>private void stopSongsServices() {
  
      for (Intent intent : songsIntentsList) {
          context.stopService(intent);
      }
  
  }
  </code></pre>
  
  <p>This is the class for <code>MusicService</code>: </p>
  
  <pre><code>public class MusicService extends Service {
  
  
      private MediaPlayer mMediaPlayer = null;
  
      public static String SONG_ID = null;
  
  
      @Override
      public void onCreate() {
          super.onCreate();
  
      }
  
      @Override
      public int onStartCommand(Intent intent, int flags, int startId) {
  
          int id = intent.getExtras().getInt(SONG_ID);
  
          mMediaPlayer = MediaPlayer.create(this,id);
  
  
          if (!mMediaPlayer.isPlaying()) {
              mMediaPlayer.start();
  
          }
  
          return START_STICKY; //START_STICKY makes service run until we call onDestroy() service to stop it
      }
  
      @Override
      public void onDestroy() {
          super.onDestroy();
  
          if (mMediaPlayer != null) {
              mMediaPlayer.release();
              mMediaPlayer = null;
          }
      }
  
      @Override
      public IBinder onBind(Intent intent) {
          return null;
      }
  
  }
  </code></pre>
  
  <p>How can I stop all this services when needed?</p>