While playing music the media buttons on my headset works great. But if I pause and wait too long the previous media app I've used starts responding to media key presses instead of the the last active one, Spotify, as is expected.
As far as I can tell the Spotify app actively removes itself from the "preferred" media button responder list judging by the out put of "adb shell dumpsys audio".
While playing music with Spotify the stack looks like this:
Remote Control stack entries:
pi: PendingIntent{41ffaf98: PendingIntentRecord{41c84ad0 android broadcastIntent}} -- pack: null -- ercvr: ComponentI
nfo{mobi.beyondpod/mobi.beyondpod.services.player.MediaButtonIntentReceiver} -- client: null -- uid: -1 -- type: 0 s
tate: 1
pi: PendingIntent{42589780: PendingIntentRecord{445a0878 mobi.beyondpod broadcastIntent}} -- pack: null -- ercvr: Com
ponentInfo{mobi.beyondpod/mobi.beyondpod.services.player.MediaButtonIntentReceiver} -- client: null -- uid: 1000 -- t
ype: 0 state: 1
pi: PendingIntent{423eccc0: PendingIntentRecord{4235b6e0 com.spotify.mobile.android.ui broadcastIntent}} -- pack: com.
spotify.mobile.android.ui -- ercvr: ComponentInfo{com.spotify.mobile.android.ui/com.spotify.mobile.android.service.Medi
aButtonReceiver} -- client: android.media.IRemoteControlClient$Stub$Proxy@42e7e350 -- uid: 10089 -- type: 0 state: 2
A while after I've paused Spotify and haven't used any other media app it looks like this:
Remote Control stack entries:
pi: PendingIntent{41ffaf98: PendingIntentRecord{41c84ad0 android broadcastIntent}} -- pack: null -- ercvr: ComponentI
nfo{mobi.beyondpod/mobi.beyondpod.services.player.MediaButtonIntentReceiver} -- client: null -- uid: -1 -- type: 0 s
tate: 1
pi: PendingIntent{42589780: PendingIntentRecord{445a0878 mobi.beyondpod broadcastIntent}} -- pack: null -- ercvr: Com
ponentInfo{mobi.beyondpod/mobi.beyondpod.services.player.MediaButtonIntentReceiver} -- client: null -- uid: 1000 -- t
ype: 0 state: 1
As you can see Spotify has mysteriously dissapeared.
Perhaps the Spotify devs missread the documentation and blog posts like http://android-developers.blogspot.se/2010/06/allowing-applications-to-play-nicer.html and thought that Spotify was a calendar app where it is expected that it unregisters after playback is done?