Service基础
来源:互联网 发布:淘宝怎么设置英文版 编辑:程序博客网 时间:2024/06/16 09:02
Service 是Android四大组件与Activity最相似的一个。它们的区别是:activity有用户界面,service没有用户界面,一直在后台运行。
1、开发Service步骤:
1) 定义一个继承Service的子类;
2) 在AndroidManifest.xml文件中配置该Service。如下:
<!--配置一个service组件-->
<service android:name="com.service.AidlService">
<!-配置可以启动该service的intent-->
<intent-filter>
<!--为该service组件的intent-filter配置action-->
<action android:name="com.service.aidl.action.AIDL_SERVICE"/>
</intent-filter>
</service>
2、运行service,有如下两种方式:
1) 通过context的startService():用这种方式启动的service与访问者没有关联,即使访问者退出了,程序仍在运行;
2) 通过context的bindService():用这种方式启动的service与访问者绑定在一起了,即访问者退出后,程序也停止。
3、service的生命周期
1) startService()方法启动的:onCreate()->onStart()->service运行中->服务被通知停止
->onDestroy()->服务被关闭;
2) bindService()方法启动的:onCreate()->onBind()->客户端与service交互中->onUnbind()
->onDestroy()->服务被关闭;
1、开发Service步骤:
1) 定义一个继承Service的子类;
2) 在AndroidManifest.xml文件中配置该Service。如下:
<!--配置一个service组件-->
<service android:name="com.service.AidlService">
<!-配置可以启动该service的intent-->
<intent-filter>
<!--为该service组件的intent-filter配置action-->
<action android:name="com.service.aidl.action.AIDL_SERVICE"/>
</intent-filter>
</service>
2、运行service,有如下两种方式:
1) 通过context的startService():用这种方式启动的service与访问者没有关联,即使访问者退出了,程序仍在运行;
2) 通过context的bindService():用这种方式启动的service与访问者绑定在一起了,即访问者退出后,程序也停止。
3、service的生命周期
1) startService()方法启动的:onCreate()->onStart()->service运行中->服务被通知停止
->onDestroy()->服务被关闭;
2) bindService()方法启动的:onCreate()->onBind()->客户端与service交互中->onUnbind()
->onDestroy()->服务被关闭;
0 0
- Service基础
- service基础
- Service基础
- Service基础
- service基础
- Service基础
- Service基础
- Service基础
- Service基础
- service基础
- Service基础
- web service 基础
- XML Web Service 基础
- XML Web Service 基础
- XML Web Service 基础
- XML Web Service 基础
- XML Web Service 基础
- XML Web Service 基础
- 关于unbuntu下mysql.h头文件找不到的问题
- #!/usr/bin/env python与#!/usr/bin/python的区别
- 关于list的愚见
- c++ primer阅读笔记-15章-3
- Ubuntu 安装 svn时 SSL handshake failed
- Service基础
- 关于NFA转RE的思路
- 嵌入式Linux中让应用程序自动启动!
- Single Number
- 安卓学习之路_20140422_BaseAdapter点击监听事件、GridView
- 删除所有 windows 自带的高级防火墙的规则
- 内存的小知识
- Mac OS X 自带输入法输入Emoji表情与颜文字
- service进阶之跨进程调用