Service 为一体的四个分量间(剩余有Activity ,内容提供商,广播),它属于后台工作,能够在后台很长一段时间执行,他没有接口。
首先从使用方式上来说来说
他有两种使用方式:
1、启动式使用Service
启动:context.startService()
结束:Service.stopSelf()
它具有自我管理的能力。不须要通过函数调用向外部组件提供数据和功能
2、绑定式使用Serviceo
1、通过服务连接(Connection)或直接获取Service状态,和数据信息
2、服务连接能够获取Service对象,所以绑定Service的组件能够调用Service中实现的方法
3、建立连接Context.bindService,停止服务连接:Context.unbindService()
生命周期。生命周期还是直接看API 上的图比較清晰
启动Service分为显示启动和隐式启动两种启动方式
隐式启动
<service android:name=".service">
<intent-filer>
<action android:name="com.android.service"/>
<intent-filer>
</service>
final Intent serviceIntent=new Intent();
serviceIntent.setAction("com.android.service");
startService(serviceIntent);
显示启动
final Intent serviceIntent=new Intent(this,service.class);
startService(serviceIntent);
假设在同一个包中。
两者都可以使用。在不同的包。
仅隐式启动
这些仅仅是一个Service一些基本的知识表示