Saturday, 7 April 2012

Andorid Service vs AsyncTask vs Handler

  • A service is an Android component that lives independently from any other components. Activities may come and go, but services can stick around, if you wish. They serve a number of roles, from managing state that multiple activities rely upon to serving as cron jobs to handling longer app widget updates.
  • AsyncTask is a class that arranges to do some work off the main application thread. From the implementer and user of the AsyncTask, how it performs that bit of magic is not generally important. In reality, it uses a thread pool and work queue. AsyncTask uses a Handler to help arrange for select bits of work to be done on the main application thread (e.g., notifying the user of progress updates).
  • Handler is a class that is tied tightly into the message queue and loop that forms the backbone of the main application thread. The primary purpose of a Handler in application code is to arrange for messages to be sent from background threads to the main application thread, mostly to arrange for updates to the UI, which cannot be done from background threads.

No comments:

Post a Comment