Difference between Android Service,Thread,IntentService and AsyncTask
来源:互联网 发布:painter软件的内存大小 编辑:程序博客网 时间:2024/05/23 19:42
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).
- Small 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
- Difference between Android Service,Thread,IntentService and AsyncTask
- Difference Between Thread and AsyncTask in Android
- Service, Thread, IntentService and AsyncTask 比较
- Service, Thread, IntentService and AsyncTask 比较
- 第三十四天Service、IntentService、Thread、AsyncTask
- Difference between STA and MTA in thread
- Difference between Daemon and Non Daemon thread?
- difference between Multi process and multi thread
- Difference between servlet and web service
- Android知识点之多线程:Thread、AsyncTask、IntentService
- Whats the difference between Thread.setPriority() and android.os.Process.setThreadPriority()
- IntentService AsyncTask,Thread
- What is the difference between a thread and a process?
- What's the difference between a thread and a process?
- What is the difference between a process and a thread?
- Multi-thread: What is the difference between OpenMP and MPI
- The Difference Between “Add Web Reference” and “Add Service Reference”
- Android - service and thread
- Maven Getting Started - 配置Jboss仓库
- java中如何避免空指针异常
- 正则表达式思考+的作用
- Linux产生随机数
- 用mysql实现oracle sequence功能
- Difference between Android Service,Thread,IntentService and AsyncTask
- 链式存储面试题-单链表反转
- 推荐两款好的js弹窗插件
- LeetCode--Path Sum
- NYOJ-115 城市平乱
- window.dialogArguments.location.reload();
- 通过CSS3 Media Query实现响应式Web设计
- ios 8 获取地理位置
- 一些优秀的文章链接地址