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"));即可。
本文介绍如何在Android应用中创建并使用MusicService。首先通过新建Service类继承自android.app.Service,并重写关键方法如onStart。其次,在Manifest.xml中声明Service组件,并设置相应的intent-filter。最后,通过startService启动MusicService。
531

被折叠的 条评论
为什么被折叠?



