Sunday 11 January 2015

What is the difference between service and intentservice in android  ? 

i  Intentservice by default will create one separate thread to handle the service functionality.
   All the startservice requests for intentservice will be routed to that thread. 
ii. Where as service by default runs in main thread. All the startservice requests will be routed to main thread by default. 
iii. While implementing a service, programmer has to implement onCreate(), onStartCommand(), and onDestroy() methods. 
iv. Where as while implementing IntentService programmer has to implement only onHandleIntent(). 
v. After starting IntentService, it will be automatically closed if there are no pending startService requests. 
vi. Where as for normal service programmer has to stop the service explicitly either by using stopSelf() or stopService() methods. 
vii. Don't try to touch UI from IntentService's onHandleIntent() method directly, as that function runs in a separate thread. (Not in main thread).

No comments:

Post a Comment