Android-Service

来源:互联网 发布:手机焓湿图计算软件 编辑:程序博客网 时间:2024/06/07 06:19

1、问题列表

1.1、service是运行在一个单独的线程?

官方原文:
Caution: A service runs in the main thread of its hosting process—the service does not create its own thread and does not run in a separate process (unless you specify otherwise). This means that, if your service is going to do any CPU intensive work or blocking operations (such as MP3 playback or networking), you should create a new thread within the service to do that work. By using a separate thread, you will reduce the risk of Application Not Responding (ANR) errors and the application's main thread can remain dedicated to user interaction with your activities.

并不是运行在一个单独的线程的,是运行在启动他的组件的主线程上的。所以如果我们需要在service中做一些耗时的操作,需要自己另外启一个线程。

1.2、service可以同时被startService()和bindService()启动吗?

官方原文:These two paths are not entirely separate. That is, you can bind to a service that was already started withstartService(). For example, a background music service could be started by calling startService() with anIntent that identifies the music to play. Later, possibly when the user wants to exercise some control over the player or get information about the current song, an activity can bind to the service by calling bindService(). In cases like this, stopService() or stopSelf() does not actually stop the service until all clients unbind.

一个service可以同时被startService()和bindService()

1.2、service的声明周期



2、demo

2.1、范德萨


3、相关链接

3.1、官方

Guide(Service):http://developer.android.com/guide/components/services.html#Notifications
Guide(BoundService):http://developer.android.com/guide/components/bound-services.html

3.2、网友


0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 领导要潜我老婆怎么办 被领导潜了该怎么办 实习期单位领导开除我我该怎么办 泡泡袖显手臂肥怎么办 客人想吃霸王餐怎么办 在四楼上课时发生地震怎么办 学生在上课时发生地震怎么办 学生上课时发生地震怎么办 老板承诺的工资不兑现怎么办 只有本科毕业证没有学位证怎么办 孩子跟坏孩子玩怎么办 苕帚跟簸箕掉下来了怎么办 身体发烫又觉得冷怎么办 买苹果8后悔了怎么办 手机死机了怎么办不可拆卸电池 百度网盘密码忘了怎么办 空调冷凝水无法排出怎么办 转账时名字错了怎么办 打款名字错了怎么办 转账名字写错了怎么办 国际汇款汇错了怎么办 汇款英文写错了怎么办 体重秤不显示了怎么办 在ur试完衣服怎么办 汽车主机没有倒车检测线怎么办 合格考补考没过怎么办 合同一式两份双方都丢失怎么办 自控力差的人怎么办 孩子缺乏自控能力该怎么办 名片上换了号码怎么办 格力空调显示u8怎么办 格力空调出现u8怎么办 双肺多发斑点影怎么办 外文翻译没5000字怎么办 睡出永久睡痕怎么办 英语不好学学英文软件怎么办 遥控汽车只能原地打转怎么办 铝合金门上的胶带纸撕不掉怎么办 纸胶带撕不下来怎么办 拼多多卖不出去怎么办 联想键盘被锁了怎么办