APP开发实战68-IntentService
2016-06-26 15:53
405 查看
17.3 IntentService
实现服务有两种方式:继承 Service 或者 IntentService ,后者是前者的子类。IntentService 将用户的请求执行在一个子线程中,用户只需覆写onHandleIntent函数,并在改函数中完成自己的耗时操作即可。在执行完毕后,IntentService 会调用stopSelf自我销毁。如果没有特别需求,继承 IntentService 是最好的选择。IntentService处理流程:
(1)创建默认的一个 worker 线程处理传递给 onStartCommand() 的所有 intent ,不占据应用的主线程。
(2)创建一个工作队列一次传递一个 intent 到你实现的 onHandleIntent() 方法,避免了多线程
(3)在启动请求被处理后自动关闭服务,不需要调用 stopSelf()。
(转自:http://www.tuicool.com/articles/iu22QnF)
相关文章推荐
- <Android 基础(八)> Palette
- <Android 基础(八)> Palette
- APP开发实战67-Service类型
- ADB WIFI,告别USB连接线
- iOS/Swift跳转界面时隐藏tabBar的方法
- DrawerLayout简单使用之实现侧滑菜单(来自于support V4包)
- Note On <You Don't Know JS - this and Object Prototypes>
- Android 访问res目录下的资源
- Android系统的常用权限
- iOS block
- Android 更新UI的方法汇总
- Android TabLayout(选项卡布局)简单用法实例分析
- iOS触摸事件/响应者链条
- Android 监听锁屏、解锁、开屏 功能代码
- iOS Image KVO
- android键盘监听
- 渲染数据统计窗口 Rendering Statistics Window
- iOS Network
- Fragment生命周期
- android开发实现微博正文效果、顶部悬浮、ScrollView嵌套ListView