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怎么用啊??谢谢了啊

解决方案 »

  1.   

    看看这个 http://www.cnblogs.com/allin/archive/2010/05/15/1736458.html
      

  2.   

    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
      

  3.   

    音乐这样的需要频繁控制,使用绑定方式比较靠谱,系统使用了AIDL的方式处理Muisc的,你可以看下Android AIDL远程服务使用示例楼上美女说的,顺序比较清晰,你记忆下比较好
      

  4.   

    如果用AIDL就用到Onbind,并且要求return一个binder对象,它是AIDL定义的接口的实现类的子类的实例