对于应用程序和服务之间的通信,我为什么要使用绑定服务而不是在 Intent 中发送数据:
mServiceIntent = new Intent(getActivity(), RSSPullService.class);
mServiceIntent.setData(Uri.parse(dataUrl));
我读到“如果服务已经在运行,它将再次使用 onStartCommand() 调用,以传递新的 Intent,但不会创建第二个副本。” 这意味着我可以发送消息以影响服务的进度,这是在 google RandomMusicPlayer 示例中所做的:
public void onClick(View target) {
// Send the correct intent to the MusicService, according to the
// button that was clicked
if (target == mPlayButton)
startService(new Intent(MusicService.ACTION_PLAY));
else if (target == mPauseButton)
startService(new Intent(MusicService.ACTION_PAUSE));
else if (target == mSkipButton)
startService(new Intent(MusicService.ACTION_SKIP));
else if (target == mRewindButton)
startService(new Intent(MusicService.ACTION_REWIND));
else if (target == mStopButton)
startService(new Intent(MusicService.ACTION_STOP));
else if (target == mEjectButton) {
showUrlDialog();
}