最近同学搞起了Android开发,自己也捡起来这个玩意来看看。这里先研究一下service
Service是安卓系统提供的四种组件之一,功能与activity类似,只不过没有activity 的使用频率高。顾名思义Service就是运行在后台的一种服务程序一般很少与用户交互,没有可视化界面。
定义一个service非常简单,只要继承就可以了,实现其中的那些方法就可以了。service必须在AndroidManifest.xml配置文件中定义
<service android:name=”myservice”>
<intent-filter>
<action android:name=”com.houyewei.action.MY_SERVICE”/>
</intent-filter>
</service>
intent-filter制定如何访问该service
onBind(Intent intent):是必须实现的一个方法返回接口
onCreate():当service第一次被创建有系统调用
onStart(Intent intent ,int startid):当通过startservice()方法启动service是该方法被调用
onDestory():当service不再使用,系统调用该方法
创建一个service代码
public classs Myservice extends Service
{
public IBinder onBind(Intent intent)
{
return null;
}
public void onCreate()
{
super.onCreate();
}
public void onStart(Intent intent ,int startId)
{
super.onStart(intent,startId);
}
public void onDestory()
{
super.onDestory();
}
}