美文网首页APP开发实战
APP开发实战68-IntentService

APP开发实战68-IntentService

作者: xjbclz | 来源:发表于2016-07-03 22:52 被阅读12次

    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)

    相关文章

      网友评论

        本文标题:APP开发实战68-IntentService

        本文链接:https://www.haomeiwen.com/subject/smscjttx.html