1.src->new->class
在Name中填入MusicService,在Superclass中填入android.app.Service
2.重写Service类中的函数,onStart(Intent intent,int startId)等
3.在Manifest.xml文件中声明:
<service android:name = "com.example.hello.MusicService">
<intent-filter >
<action android:name = "com.yarin.Android.MUSIC"/>
<category android:name = "android.intent.category.DEFAULT"/>
</intent-filter>
</service>
注:本文所用工程名为hello
4.调用时只需在相应位置调用startService(new Intent("com.yarin.Android.MUSIC"));即可。