Resources for Android Development
This work by José Juan Sánchez Hernández is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
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 (API Level 11 Introduces the executeOnExecutor() method). |
Trigger | Call to method onStartService() |
Thread start() method |
Intent | Call to method execute() |
Original: Comparisons. [Tejas Lagvankar]