我有一个RecyclerView显示设备上找到的所有歌曲。
适配器类
holder.constraintLayout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//Store songList and songIndex in mSharedPreferences
storageUtil.storeSong(Main.musicList);
storageUtil.storeSongIndex(holder.getAdapterPosition());
//Send media with BroadcastReceiver
Intent broadCastReceiverIntent = new Intent(Constants.ACTIONS.BROADCAST_PlAY_NEW_SONG);
sendBroadcast(broadCastReceiverIntent);
Intent broadCastReceiverIntentUpdateSong = new Intent(Constants.ACTIONS.BROADCAST_UPDATE_SONG);
sendBroadcast(broadCastReceiverIntentUpdateSong);
}
});
我想要实现的是,当在RecyclerView中单击一首歌曲时,一个广播被发送到我的服务类,因此一首歌曲开始播放。
sendBroadcast 无法解决,那么如何从我的适配器类发送广播意图?
我也想知道这是否是正确的方法,或者是否有更好的方法在适配器中发送广播,因为我在某处读到BroadcastReceivers不属于适配器类。
慕容708150
相关分类