多线程、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 ...
随机推荐
- 你好,C++(34)有一只叫做多利的羊 6.2.4 拷贝构造函数
6.2.4 拷贝构造函数 在C++世界中,除了需要使用构造函数直接创建一个新的对象之外,有时还需要根据已经存在的某个对象创建它的一个副本,就像那只叫做多利的羊一样,我们希望根据一只羊创建出来另外一只 ...
- underscorejs-pluck学习
2.14 pluck 2.14.1 语法: _.pluck(list, key) 2.14.2 说明: pluck方法根据key对list数组中的每个对象进行检索,返回检索成功的属性值,否则返回und ...
- 50 Pow(x, n)(求x的n次方Medium)
题目意思:x为double,n为int,求x的n次方 思路分析:直接求,注意临界条件 class Solution { public: double myPow(double x, int n) { ...
- yii2源码学习笔记
assets 前端资源文件夹,用于管理css js等前端资源文件等 commands 包含命令行命令,文件为控制器文件 config 应用的配置文件 controllers 控制器文件 mai ...
- UIAlertView的使用方法
UIAlertView的使用方法 1. 最简单的用法 UIAlertView*alert = [[UIAlertView alloc]initWithTitle:@"提示" mes ...
- django + nginx + raspberypi + pidaro
对于一个从事后台开发的人来说,搞了个网站,我自己都觉得有点意外.不是很懂html,不是很懂css,不是很懂js,不是很懂web开发模式/框架,不是很懂httpd/nginx--,web的东西样 ...
- SQL(二) 将一张表数据插入另外一张表
INSERT INTO BaomingRelation ([BaomingID] ,[RelationNumber] ,[UserID] ,[Area]) SELECT BaomingID,NEWID ...
- 第一个Windows程序讲解
上次,我们一起写了第一个Windows程序,虽然程序非常简单,但是它却可以帮助大家建立学好windows开发的信心. 今天,就让我帮助大家分析一下这个程序的内容.首先,我们的程序包含了一个头文件:wi ...
- COCI2014-2015CONTEST#7——POLICE
http://www.hsin.hr/coci/archive/2014_2015/contest7_tasks.pdf [题目描述] 有N个书架,每个书架可以容纳M本书.给出了若干本书,每本书有一个 ...
- HDOJ 2092 整数解(2次方程整数解公式)
Problem Description 有二个整数,它们加起来等于某个整数,乘起来又等于另一个整数,它们到底是真还是假,也就是这种整数到底存不存在,实在有点吃不准,你能快速回答吗?看来只能通过编程. ...