#Android Development What are the main differences between a - TopicsExpress



          

#Android Development What are the main differences between a service and an Intent Service and when you should use it? --Service is a base class of service implementation. Service class is run in the application’s main thread which may reduce the application performance. Thus, IntentService, which is a direct subclass of Service is borned to make things easier. The IntentService is used to perform a certain task in the background. Once done, the instance of IntentService terminate itself automatically. Examples for its usage would be to download a certain resources from the Internet. Differences Service class uses the application’s main thread, while IntentService creates a worker thread and uses that thread to run the service. IntentService creates a queue that passes one intent at a time to onHandleIntent(). Thus, implementing a multi-thread should be made by extending Service class directly. Service class needs a manual stop using stopSelf(). Meanwhile, IntentService automatically stops itself when there is no intent in queue. IntentService implements onBind() that returns null. This means that the IntentService can not be bound by default. IntentService implements onStartCommand() that sends Intent to queue and to onHandleIntent(). In brief, there are only two things to do to use IntentService. Firstly, to implement the constructor. And secondly, to implement onHandleIntent(). For other callback methods, the super is needed to be called so that it can be tracked properly. In short A Service is a broader implementation for the developer to set up background operations, while an IntentService is useful for “fire and forget” operations, taking care of background Thread creation and cleanup.
Posted on: Mon, 02 Sep 2013 07:18:37 +0000

Trending Topics



Recently Viewed Topics




© 2015