首先Service是四大组建之一,Service的优先级比Activity等级高。Service没有用户界面,可以解决两个不同Android应用程序之间的调用和通信问题。
下面介绍一下Service的两种使用方法:
一种是启动方式使用的Service(startservice),另一种是绑定式使用Service(Bound Service)。
以启动式方式分为下面两种:
显示启动:Intent intent=new Intent(this,RandomService.class);
StartService(serviceIntent);
隐身启动:先注册需要隐身启动的Service
<service android:name=".service.Notification.Service">
<intent-filter >
<action android:name="startService"/>
</intent-filter>
</service>
隐身启动的代码 Intent Intent=new Intent();
serviceintent.setAction("startService");
以绑定方式使用service:
intent serviceIntent=new Intent(this,MathSevrvice.class);
bindService(serviceIntent,mConnection,Context.BIND_AUTO_CREATE)