IntentService
来源:互联网 发布:开票软件系统初始化 编辑:程序博客网 时间:2024/06/07 19:18
1. Service缺点:Service默认运行在主线程即UI线程,所以如果Service运行耗时或可能堵塞的操作时,你的APP可能出现ANR错误;
2. IntentService特点:
A.生成一个默认且与主线程互相独立的工作者线程来执行所有传送至onStartCommand方法的Intent;
B.生成一个工作队列来传送Intent对象给onHandleIntent方法,同一时刻只能传送一个Intent对象,从而避免多线程问题;
C.在所有的请求Intent都被执行完后自动停止服务,不需要自己去调用stopSelf方法来停止该服务;
D.提供onBind方法的默认实现,返回null;
E.提供onStartCommand方法默认实现,它将Intent先传送至工作队列,然后从工作队列中每次取出一个传送至onHandleIntent方法,该方法中对Intent进行处理;
3.开发:继承IntentService,创建无参构造方法,重写onHandleIntent方法
4.源码分析:继承自Service、内部有继承自Handler的内部类;
5. 特殊方法:setIntentRedelivery():
设为true:onStartCommand返回START_REDELIVER_INTENT,如果onHandleIntent在返回之前进程死掉了,那么进程将会重启,Inent重新投送,如果有大量的Intent要投送,则只保证最近的Intent会被重新投送
0 0
- IntentService
- IntentService
- intentservice
- IntentService
- IntentService
- IntentService
- IntentService
- IntentService
- IntentService
- IntentService
- IntentService
- IntentService
- IntentService
- IntentService
- IntentService
- IntentService
- IntentService
- intentservice
- 如何优化JAVA代码及提高执行效率
- Service
- 欧拉工程第1题 找出1000以下自然数中3和5的倍数之和
- android Dialog
- HTTP 方法:GET 对比 POST
- IntentService
- C#版 Socket编程(最简单的Socket通信功能)
- 浅谈yarn的调度模式
- spring mvc与mybatis与maven+mysql框架整合
- SAP MM 评估类型 评估类别
- VC++ debug assertion failed
- MySQL索引原理及慢查询优化
- MD5加密
- 解决UICollectionView间隔设置为0时仍有空隙的问题