多线程、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 ...
随机推荐
- Windows Phone获得IsolatedStorage中指定目录下的所有文件
在Windows Phone 中对隔离存储空间中的文件操作需要通过System.Io.IsolatedStorage下的类进行操作 获得指定文件夹下的所有文件: 参数:是指定文件夹的路径加上通配符,格 ...
- SCXML和QScxml使用总结
最近接触了SCXML这个状态描述文本,简单来讲就是描述了整个状态的变迁过程的一种XML格式的表格.Qt labs中有一个项目就是QScxml,它基于QStateMachine上层制作,可以直接读取SC ...
- oracle删除用户所有的表
删除用户所有的表,带有级联关系: --创建存储过程 CREATE OR REPLACE PROCEDURE DROPTABLES IS V_SQL ); CURSOR CUR IS SELECT TA ...
- javascript特殊运算符(in,instanceof,typeof,delete,void,逗号)
in运算符 in运算符要求其左边的运算数是一个字符串,或可以被转换为字符串,右边的运算数十一个对象或数组.如果该 运算符左边的值是右边对象的一个属性名,则返回true, ...
- C# 中使用 OpenSSL 的公钥/私钥进行加密和解密
在C#中进行RSA解密,需要用RSACryptoServiceProvider,但是不支持OpenSSL格式的公钥或者私钥. X509 公钥 -----BEGIN PUBLIC KEY----- MI ...
- Freemarket学习笔记(一)
一.常用三个指令 1.if指令 a.<#if condition></#if> b.<#if condition><#else></#if> ...
- python+flask+mongodb+whoosh实现自己的搜索引擎(一):目录
python+flask+jieba+mongodb+whoosh实现自己的搜索引擎 一.目录 二.基于python的爬虫 三.网页去燥,URL去重 四.基于mongodb的数据存储 五.基于whoo ...
- Phalcon 的分流bootstrap 设计 主程序入口
<?php use \Phalcon\DI\FactoryDefault as PhDi; error_reporting(E_ALL); date_default_timezone_set(' ...
- uva 580 危险的组合(排列组合)
Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & %llu Submit Status Descript ...
- python设计模式之观察者模式
观察者模式 当对象间存在一对多关系时,则使用观察者模式(Observer Pattern).比如,当一个对象被修改时,则会自动通知它的依赖对象.观察者模式属于行为型模式. 观察者模式在状态检测和事件处 ...