多线程、Service与IntentService的比较
|
|
Service
|
Thread
|
IntentService
|
AsyncTask
|
|
When to use ?
|
Task with no UI, but shouldn't be too long. Use threads within service for long tasks.
|
- Long task in general.
- For tasks in parallel use Multiple threads (traditional mechanisms) |
- Long task usually with no communication to main thread.
(Update)- If communication is required, can use main thread handler or broadcast intents - When callbacks are needed (Intent triggered tasks). |
- Small task having to communicate with main thread.
- For tasks in parallel use multiple instances OR Executor |
|
Trigger
|
Call to method
onStartService() |
Thread start() method
|
Intent
|
Call to method execute()
|
|
Triggered From (thread)
|
Any thread
|
Any Thread
|
Main Thread (Intent is received on main thread and then worker thread is spawed)
|
Main Thread
|
|
Runs On (thread)
|
Main Thread
|
Its own thread
|
Separate worker thread
|
Worker thread. However, Main thread methods may be invoked in between to publish progress.
|
|
Limitations /
Drawbacks |
May block main thread
|
- Manual thread management
- Code may become difficult to read |
- Cannot run tasks in parallel.
- Multiple intents are queued on the same worker thread. |
- one instance can only be executed once (hence cannot run in a loop)
- Must be created and executed from the Main thread |
多线程、Service与IntentService的比较的更多相关文章
- Android之Service与IntentService的比较
Android之Service与IntentService的比较 不知道大家有没有和我一样,以前做项目或者练习的时候一直都是用Service来处理后台耗时操作,却很少注意到还有个IntentServ ...
- Android中Service与IntentService的使用比较
不知道大家有没有和我一样,以前做项目或者练习的时候一直都是用Service来处理后台耗时操作,却很少注意到还有个IntentService,前段时间准备面试的时候看到了一篇关于IntentServic ...
- Android Service 与 IntentService
Service 中的耗时操作必须 在 Thread中进行: IntentService 则直接在 onHandleIntent()方法中进行
- [Android] Service和IntentService中显示Toast的区别
1. 表象 Service中可以正常显示Toast,IntentService中不能正常显示Toast,在2.3系统上,不显示toast,在4.3系统上,toast显示,但是不会消失. 2. ...
- service and intentservice
Service是Android中四大组件之一,在Android开发中起到非常重要的作用,先来看一下官方对Service的定义: A Service is an application componen ...
- Android查缺补漏--Service和IntentService
Service的运行不依赖界面,即使程序被切换到后台,Service仍然能够保持正常运行.当某个应用程序进程被杀掉时,所有依赖于该进程的Service也会停止运行. Service 分为启动状态和绑定 ...
- Android Service、IntentService,Service和组件间通信
Service组件 Service 和Activity 一样同为Android 的四大组件之一,并且他们都有各自的生命周期,要想掌握Service 的用法,那就要了解Service 的生命周期有哪些方 ...
- Service 和 IntentService的区别;
Srevice不是在子线程,在Srevice中做耗时操作一样ANR,然后我们就会用到IntentService,IntentSrevice不但擅长做耗时操作,还有一个特点,用完即走: 在Srevice ...
- android拾遗——Android之Service与IntentService的比较
不知道大家有没有和我一样,以前做项目或者练习的时候一直都是用Service来处理后台耗时操作,却很少注意到还有个IntentService,前段时间准备面试的时候看到了一篇关于IntentServic ...
随机推荐
- 网络编程Socket之TCP
服务端: 1. 创建 ServerSocket 对象并监听一个端口 2. 调用accept()方法等待客户端的连接(阻塞式) 3. 输入流(记取客户端发送过来的数据) 4. 输出流(响 ...
- Java数据库连接池的几种配置方法(以MySQL数据库为例)
Java数据库连接池的几种配置方法(以MySQL数据库为例) 一.Tomcat配置数据源: 前提:需要将连接MySQL数据库驱动jar包放进Tomcat安装目录中common文件夹下的lib目录中 1 ...
- JVM调优实践-Tomcat调优
调优几个重要指标 GC频率 提升每次GC的效率 准备环节 jmeter的配置 未压测前JVM配置 工程未调优前配置 -Xms400m -Xmx400m -XX:PermSize=64m -XX:Max ...
- TalkingData游戏版本在Cocos2d-x 3.2使用
最近一直忙别的方面的事情,没有太关注cocos2dx的发展情况,竟然已经更新到了3.2的版本,总的来说3.2比较3.0在使用上会有一些路径的变成,包括ios的引用路径和android上的build的p ...
- Qt中绘图坐标QPainter,Viewport与Window的关系
在Qt中常常要自己重载一些paintEvent函数,这个时候往往忽略了两个很关键的API,那就是setViewport和setWindow. Viewport,顾名思义,反应的是物理坐标,就是你实际想 ...
- socket (转,吴秦,http://www.cnblogs.com/skynet/archive/2010/12/12/1903949.html)
Linux Socket编程(不限Linux)2010-12-12 21:58 by 吴秦 我们深谙信息交流的价值,那网络中进程之间如何通信,如我们每天打开浏览器浏览网页时,浏览器的进程怎么与web ...
- CSS 字体描边
-webkit-text-stroke: 2px #; text-stroke: 2px #; -o-text-stroke: 2px #;
- css 属性之绝对定位
<html><head><style type="text/css">h2.pos_abs{position:absolute;left:100 ...
- Scrapy使用以及Xpath的一些坑, 再入剁手
scrapy爬虫: https:www.scrapy.org 本篇博客依托的项目: https://github.com/viciousstar/BitcointalkSpider/ 一. Scrap ...
- ctags使用详解(转载)
一. ctags是干什么的 ctags的功能:扫描指定的源文件,找出其中所包含的语法元素,并将找到的相关内容记录下来. 我用的是Exuberant Ctags,在Windows上使用,就 ...