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怎么用啊??谢谢了啊
{
//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怎么用啊??谢谢了啊
context.startService() ->onCreate()- >onStart()->Service running
context.stopService() | ->onDestroy() ->Service stop 使用使用context.bindService()启动Service会经历:
context.bindService()->onCreate()->onBind()->Service running
onUnbind() -> onDestroy() ->Service stop