How to create a service with single thread? should I use IntentService or As yncTask?

A. Use IntentService, if you don't want to interact with UI.
B. Use AsyncTask if you want to interact with UI.
C. both option 1 and option 2 are correct.
D. none


Answer: C

Description: 
It actually depends on the requirement. Use IntentService, if you don't want to interact with UI. Use AsyncTask if you want to interact with UI from background thread. It doesn't mean that you can't touch UI from IntentService, but you have to either use post() or runOnUiThread() or Handler concepts, which are little bit complicated to understand for novice android developers who are not well versed with threads.

No comments:

Post a Comment