IntentService 使用

来源:互联网 发布:php5.0不支持php版本 编辑:程序博客网 时间:2024/06/07 16:09

IntentService 使用
博客地址:
http://blog.csdn.net/lmj623565791/article/details/47143563
IntentService的使用
她是Service的子类,用来处理异步请求,通过startService(intent)方法,把intent传递给IntentService,
IntentService在创建的时候,会通过HandlerThread单独开启一个线程来处理所有的startService(intent),的Intet请求对象
这样避免事务阻塞主线程,IntentService在处理事务的时候,还是采用Handler方式的,创建了一个ServiceHandler的内部Hnadler
并且绑定了HandlerThread所对应的子线程,ServiceHandler把所有的Intent都封装在一个onHandlerIntent的虚函数里面,
所有我们直接实现onHandlerIntent方法,更具Intent不同做不同事情

注意:在执行完了一个Intent请求对象的工作之后,如果没有新的intent发送过来,就会自动停止Service,否则执行下一个Intent所对应的任务
原创粉丝点击