title: App does not become the preferred MediaButtonReceiver when calling setActive(true) a second time
body: <p>I have tried to implement media button control per <a href="https://youtu.be/XQwe30cZffg?t=20m21s">Google's talk</a></p>
  
  <p>I set the receiver in manifest:</p>
  
  <pre><code>&lt;receiver android:name="android.support.v4.media.session.MediaButtonReceiver"&gt;
      &lt;intent-filter&gt;
          &lt;action android:name="android.intent.action.MEDIA_BUTTON" /&gt;
      &lt;/intent-filter&gt;
  &lt;/receiver&gt;
  
  &lt;service android:name=".player.PlayFileService"&gt;
      &lt;intent-filter&gt;
          &lt;action android:name="android.intent.action.MEDIA_BUTTON" /&gt;
      &lt;/intent-filter&gt;
  &lt;/service&gt;
  </code></pre>
  
  <p>create the <code>MediaSessionCompat</code> in <code>onCreate()</code> of Service:</p>
  
  <pre><code>    mediaSession = new MediaSessionCompat(getApplicationContext(), "SOUNDPROCESS");
      mediaSession.setFlags(MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS | MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS);
      PlaybackStateCompat ps = new PlaybackStateCompat.Builder()
              .setActions(PlaybackStateCompat.ACTION_PLAY | PlaybackStateCompat.ACTION_PAUSE | PlaybackStateCompat.ACTION_PLAY_PAUSE)
              .build();
      mediaSession.setPlaybackState(ps);
      mediaSession.setCallback(new MediaSessionCompat.Callback() {
          @Override
          public void onPlay() { ...
             }
      });
  </code></pre>
  
  <p>and handle the intent in <code>onStartCommand()</code></p>
  
  <pre><code>MediaButtonReceiver.handleIntent(mediaSession, intent);
  </code></pre>
  
  <p>I then call <code>setActive(true);</code> when I gain audio focus, and <code>setActive(false);</code> when I stop playback. This works the first time, my app becomes the preferred media button receiver and receives callbacks.</p>
  
  <p>However, if I stop playback in my app, go into another app like Google Play Music and start playback there, then return to my app and call <code>setActive(true)</code> Google Play Music continues to receive the callback and the media buttons don't work in my app.</p>
  
  <p>From my understanding, the last call to <code>setActive(true)</code> should take precedence. I have verified that <code>isActive()</code> returns true. I can also work around the issue by creating a new <code>MediaSessionCompat</code> each time, but this doesn't seem ideal.</p>
  
  <p>How can I make my app become the preferred media button receiver every time I call <code>setActive(true)</code>?</p>
  
  <p>UPDATE: Minimum project to reproduce the problem here: <a href="https://github.com/svenoaks/MediaButtonDemo.git">https://github.com/svenoaks/MediaButtonDemo.git</a></p>
  
  <p>Steps to reproduce:</p>
  
  <ol>
  <li>Run app, press the PLAY button. <code>setActive(true)</code> is called and
      MediaButtonReceiver is now the preferred media button.</li>
  <li>Press play/pause button on wired or wireless headphones or other
  media button. Toast shows indicating that callback is working.</li>
  <li>Start playback on another app such as Google Play Music which
  supports media buttons. Press pause on this app.</li>
  <li>The demo app can no longer be the preferred media button receiver,
  even if PLAY button is pressed again, calling <code>setActive(true)</code>
  again. The other app always responds to media buttons.</li>
  </ol>
  
  <p>This was tested on Android 6.0.</p>