对于应用程序和服务,为什么我会用绑定的服务,而不是在Intent发送数据之间的通信:
mServiceIntent = new Intent(getActivity(), RSSPullService.class);
mServiceIntent.setData(Uri.parse(dataUrl));
我读了“如果服务已在运行,它将被onStartCommand()再次呼吁,为客户提供新的意图,但不是会创建第二个副本。” 这意味着我能实现这一意图将消息发送到影响服务的进步,这是在谷歌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();
}