Android service 小研究
2011-12-03 19:55
204 查看
最近同学搞起了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();
}
}
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();
}
}
相关文章推荐
- Android Service 通知Activity更新界面的方法研究
- Android Service 通知Activity更新界面的方法研究|Service通过Broadcast更新UI
- Android Service 通知Activity更新界面的方法研究
- Android中深入研究Service
- Android Service 通知Activity更新界面的方法研究|Service通过Broadcast更新UI
- Android中深入研究Service
- android的service的研究
- Android启动过程研究(三:servicemanager进程与Binder通信机制)
- Android中深入研究Service
- Android Service 通知Activity更新界面的方法研究
- android Application Component研究之Service
- Android Service 通知Activity更新界面的方法研究
- [Android 系统源代码研究] ActivityManagerService情景分析
- android开发 关于Service的研究
- android WindowManagerService addFakeWindow 研究
- android service学习与研究
- Android多媒体研究之mediaservice
- android service学习与研究
- Android Service 通知Activity更新界面的方法研究
- android Application Component研究之Service