IntentService解析

IntentService使用工作队列在主线程外执行耗时任务,维护一个工作线程和消息处理对象。它在onCreate()中启动工作线程,onStart()发送任务请求,ServiceHandler在工作线程中按序处理任务,每次只处理一个。用户只需覆写onHandleIntent()进行具体任务处理。
摘要由CSDN通过智能技术生成


    IntentService使用一个工作队列来从Application的主线程中分担任务,这些任务往往做着比较耗时的工作。IntentService维护着一个工作线程消息处理对象(Handler),通过在工作线程中创建消息循环(Looper)和消息队列(MessageQueue)来以队列的方式处理任务,一次只能处理一个任务,上一个任务请求完成后才接着处理下一个任务请求。

    IntentService继承自Service,也就是说IntentService具有Service的一切特性。客户端可以通过startService(Intent)   来发送一个任务请求,如果IntentService还未创建的话,会调用onCreate()方法 

     @Override
    public void onCreate() {
        // TODO: It would be nice to have an option to hold a partial wakelock
        // during processing, and to have a static startService(Context, Intent)
        // method that would launch the service & hand off a wakelock.
        super .onCreate();
        HandlerThread thread = new HandlerThread("IntentService[&
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值