java - How to click song list (Now Playing activity) to playing without (Music Preview) startActivity -
how click , send (intent + putextras + startactivity) in main activity (music preview activity) , playing song without showing it. song list stays, clicking list song --> refresh music preview activity. want stay activity (song list) music priview activity intent , refreshing , playing new song.
song list :
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); }
you use broadcastreceiver
this.
private final broadcastreceiver mhandlemessagereceiver = new broadcastreceiver(){ @override public void onreceive(context context, intent intent) { //get music data intent string position = intent.getstringextra("pos"); ... } };
register broadcastreciever
intent
in nowplayingactivity's oncreate()
this,
registerreceiver(mhandlemessagereceiver, new intentfilter("songchange"));
and don't forget unregister receiver ondestroy()
.
unregisterreceiver(mhandlemessagereceiver);
and in playlistactivity on list item click this,
intent intent = new intent("songchange"); intent.putextra("pos", position); ...//pass needed data sendbroadcast(intent);
Comments
Post a Comment