0

如何在主要活动(音乐预览活动)中单击并发送(Intent + putExtras + startActivity)并播放歌曲而不显示它。歌曲列表保留,但单击列表歌曲 --> 刷新音乐预览活动。我想保留此活动(歌曲列表),但音乐预览活动会变得有意图并令人耳目一新并播放新歌。

http://www.pixentral.com/pics/1MpvIjTXByBNfFasIZ0UFI2SbkS11.jpg http://www.pixentral.com/pics/1MpvIjTXByBNfFasIZ0UFI2SbkS11.jpg

歌单:

public void onClick(View v) {

            Intent intent = new Intent(mContext, MusicPreview.class);
            intent.putExtra("pos", position).putExtra("names", SongsName).putExtra("songlist", SongsUri);
            mContext.startActivity(intent);

        }
4

1 回答 1

1

您可以BroadcastReceiver为此使用 a 。

private final BroadcastReceiver mHandleMessageReceiver = new BroadcastReceiver(){
        @Override
        public void onReceive(Context context, Intent intent) {
            //Get all your music data from the intent
            String position = intent.getStringExtra("pos");
            ...
        }
 };

像这样在您的 NowPlayingActivity 中注册它BroadcastRecieverIntentonCreate()

registerReceiver(mHandleMessageReceiver, new IntentFilter("songchange"));

并且不要忘记取消注册接收者onDestroy()

unregisterReceiver(mHandleMessageReceiver);

然后在列表项上的 PlaylistActivity 中单击执行此操作,

Intent intent = new Intent("songchange");
intent.putExtra("pos", position);
...//pass all the needed data
sendBroadcast(intent);
于 2015-06-01T05:02:22.800 回答