多线程、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 ...
随机推荐
- 跟我学android-Notification
Notification 可以理解为通知的意思,会出现在通知栏,比如来了一条短信 使用 Notification 有以下3个步骤: 1. 创建 NotificationManager的对象 2.为No ...
- NHibernate考察实例:简单映射
建立一个Company类用来测试,对应的表为TBLCOMPANY. 1. 下载NHibernate(版本1.2.0.CR1),将NHibernate \bin\net-2.0下面的文件拷贝到lib ...
- locate 不能使用
当需要查找一个文件,只知道文件名不知道路径,我们通常用locate,由于公司的服务器使用最小化安装的所以当locate 文件名,报错,提 示-bash: locate: command not fou ...
- 面向对象设计模式之TemplateMethod模板方法(行为型)
动机:在软件构建过程中,对于某一项任务,他常常有稳定的整体操作结构,但各个子步骤却有很多改变的需求,或者由于固有的原因(比如框架与应用之间的关系)而无法和任务的整体结构同时实现:如何在确定稳定操作结构 ...
- 插入数据前设置字符编码为utf8
xxx.php保存时选择utf8编码,页头最好加上 header('conten-type:text/html;charset=utf-8'); 在执行CRUD操作前先执行一下 mysql_query ...
- Python学习笔记:03语法
Python 语法 Python语法包括: 模块函数导入 赋值 判断循环语句 模块导入 import somemodule somemodule.somefunc from somemodule im ...
- CSS实现table td中文字的省略与显示
所谓省略就是把多余的字以“...”显示出来,而显示则是当鼠标移动到td上时,把省略的字重新显示出来.对于一个table,兼容IE与FF.Chrome的省略方式CSS写法: table{ width:2 ...
- C语言笔记(枚举)
关于枚举,在我以前写程序的时候,几乎是没有使用过的,只是偶尔会在一下别人写的驱动库中有看到过.今天看了朱老师的视频,准备将枚举相关的东西总结一下. 一.关于枚举,你需要知道 (1)在C语言中就是一些符 ...
- 通过Web Deploy方式部署WCF
如何发布WCF, 其实它有很多种方式去发布WCF服务到IIS上,这篇文章将介绍通过Web Deploy的发布方式去部署. 步骤: 在IIS上创建一个网站 打开IIS, 右击“Site” -> & ...
- Linux前传——今天的学习
感觉每天早上搞一个C语言的趣味题,很不错,算是比较实际的事情了.而且,好多都不会,主要是算法,也有很多语法不知道,这样补强很有用.嵌入式方面的课题进展有条不紊,感觉相关寄存器和I/O的使用必须通过大量 ...