Service, Thread, IntentService and AsyncTask 比较
来源:互联网 发布:淘宝网网上购物 编辑:程序博客网 时间:2024/06/06 14:35
From http://madhusudhanrc.blogspot.com/2012/05/difference-between-android.html
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)
- 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).
(Update)- If communication is required, can use main thread handler or broadcast intents
- When callbacks are needed (Intent triggered tasks).
- Long task having to communicate with main thread.
- For tasks in parallel use multiple instances OR Executor
- For tasks in parallel use multiple instances OR Executor
Trigger
Call to method
onStartService()
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
Drawbacks
May block main thread
- Manual thread management
- Code may become difficult to read
- Code may become difficult to read
- Cannot run tasks in parallel.
- Multiple intents are queued on the same worker thread.
- 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
- Must be created and executed from the Main thread
0 0
- Service, Thread, IntentService and AsyncTask 比较
- Service, Thread, IntentService and AsyncTask 比较
- Difference between Android Service,Thread,IntentService and AsyncTask
- 第三十四天Service、IntentService、Thread、AsyncTask
- IntentService AsyncTask,Thread
- IntentService和Service比较
- Thread ,Service 和 AsyncTask
- Thread、AsycTask、IntentService的比较
- Thread、AsycTask、IntentService的比较
- Android知识点之多线程:Thread、AsyncTask、IntentService
- Thread and AsyncTask
- Service 和 IntentService 的比较
- IntentService和Service的比较
- Service与IntentService的比较
- Service与IntentService的比较
- 【service】 Service与IntentService的比较
- Service、IntentService、Thread的区别和联系
- Android之Service与IntentService的比较
- (面试题)c++内存分配函数有哪些?
- ZOJ 3469 Food Delivery(DP)
- unity3d游戏开发之血条与名字的设置
- CentOS下yum安装mysql,jdk以及tomcat
- C#使用LitJson解析JSON
- Service, Thread, IntentService and AsyncTask 比较
- ubuntu 安装SSH并设置免密码登录
- Lua获取当前时间
- **HDU-1233 还是通畅工程 ACM解题报告(kruskal+并查集求最小生成树)
- Mac下MySQL卸载方法
- Android自定义View-------为什么重写onMeasure()以及怎么重写
- premature end of file错误
- 04-0. 求符合给定条件的整数集(15)
- Lua5.3版本新特性