关于音乐播放器中service的使用方法解决方案

关于音乐播放器中service的使用方法
public class MusicService extends Service
{
//MediaPlayer对象
private MediaPlayer player;

public IBinder onBind(Intent arg0)
{
return null;
}

public void onStart(Intent intent, int startId)
{
super.onStart(intent, startId);
//这里可以理解为装载音乐文件
player = MediaPlayer.create(this, R.raw.test);
//开始播放
player.start();
}

public void onDestroy()
{
super.onDestroy();
//停止音乐-停止Service
player.stop();
}

}
onBind这一行是什么总用啊;
还有onstart怎么用啊??谢谢了啊


------解决方案--------------------
Service的启动有两种方式:context.startService() 和 context.bindService()。

使用context.startService() 启动Service是会会经历:
context.startService() ->onCreate()- >onStart()->Service running
context.stopService() | ->onDestroy() ->Service stop 

使用使用context.bindService()启动Service会经历:
context.bindService()->onCreate()->onBind()->Service running
onUnbind() -> onDestroy() ->Service stop

------解决方案--------------------
音乐这样的需要频繁控制,使用绑定方式比较靠谱,系统使用了AIDL的方式处理Muisc的,你可以看下

Android AIDL远程服务使用示例

楼上美女说的,顺序比较清晰,你记忆下比较好