Service
来源:互联网 发布:win8未激活网络怎么办 编辑:程序博客网 时间:2024/06/02 16:55
1. Service(服务)与Activiy都间接继承于Context。简单理解为是后台与前台的区别。
Service也要在AndroidManifest.xml里面声明。
A Service is not a separate process. The Service object itself does not imply it is running in its own process; unless otherwise specified, it runs in the same process as the application it is part of.
A Service is not a thread. It is not a means itself to do work off of the main thread (to avoid Application Not Responding errors).
2.在Service中逻辑添加在onCreate和onStart中,如果做一些很耗时间的事情,最好在Service里启动一个线程来完成,因为Service是跑在主线程中,会影响到UI操作或者阻塞主线程中的其他事情.
3.两种启动方式(1).启动执行过程:context.startService(intent)->onCreate()->onStart()->服务运行,其中onCreate可以进行一些服务的初始化工作,onStart()则启动服务。
停止执行过程下:context.stopService(intent)->onDestroy()->服务停止。 http://blog.sina.com.cn/s/blog_5e32cc130100gvc7.html).启动执行过程:context.bindService(intent)->onCreate()->onBind()->服务运行(2停止执行过程下:context.unbindService()->onDestroy()->服务停止。
4. If we want to make this service run in a remote process (instead of the standard one for its .apk), we can use android:process
in its manifest tag to specify one:
<service android:name=".app.MessengerService" android:process=":remote" />
Note that the name "remote" chosen here is arbitrary, and you can use other names if you want additional processes. The ':' prefix appends the name to your package's standard process name.
- Service
- Service
- service
- Service
- service
- Service
- Service
- service
- Service
- Service
- Service
- service
- service
- Service
- Service
- Service
- Service
- Service
- java单例模式
- 动态创建2
- AntPile简介
- Android的垃圾回收机制(android refbase类(sp wp))
- Windows下LAMP环境搭建
- Service
- CMS开发错误记录2011-01-10-001
- Android 采用pull生成XML数据
- 心殇
- php中的 引用
- Debian Linux and Orange 3G
- (转)XMLHTTPRequest对象原理介绍与应用
- Android根据Button状态(normal,focused,pressed)显示不同背景图片
- 源码格式化工具Astyle及编辑器集成