Skip to main content

What is the difference b/w Service and Intent service in android?

Service : 

  1. The Service can be used in tasks with no UI, but shouldn't be too long. If you need to perform long tasks, you must use threads within Service. 
  2. The Service is triggered by calling method startService().
  3. The Service runs in background but it runs on the Main Thread of the application.
  4. The Service may block the Main Thread of the application.
  5. If you implement a Service, it is your responsibility to stop the service when its work is done, by calling stopSelf() or stopService(). (If you only want to provide binding, you don't need to implement this method).
 Intent Service : 
  1. The IntentService can be used in long tasks usually with no communication to Main Thread. If communication is required, can use Main Thread handler or broadcast intents. Another case of use is when callbacks are needed (Intent triggered tasks).
  2. The IntentService is triggered using an Intent, it spawns a new worker thread and the method onHandleIntent() is called on this thread.
  3. The Service and IntentService may be triggered from any thread, activity or other application component
  4. The IntentService runs on a separate worker thread.
  5. The IntentService cannot run tasks in parallel. Hence all the consecutive intents will go into the message queue for the worker thread and will execute sequentially.
  6. The IntentService stops the service after all start requests have been handled, so you never have to call stopSelf().

Comments

Popular posts from this blog

Design Android Tool bar with constraint layout

 Toolbar in Android plays a very important role in quick page movement.  Steps to implement toolbar in Android 1. Create a layout file toolbar.xml in r es/layout directory 2. add below code into your toolbar.xml file. 3. Customize this as per your requirement <? xml version ="1.0"  encoding ="utf-8" ?> <layout xmlns: android ="http://schemas.android.com/apk/res/android" xmlns: app ="http://schemas.android.com/apk/res-auto" xmlns: tools ="http://schemas.android.com/tools" > <androidx.appcompat.widget.Toolbar android :id ="@+id/toolbar" android :layout_width ="match_parent" android :layout_height ="?attr/actionBarSize" android :background ="@color/colorPrimaryDark" app :elevation ="0dp" app :layout_collapseMode ="pin" > <androidx.constraintlayout.widget.ConstraintLayout android ...

Android Studio ADB is not responding manually kill adb Server

I was using Ubuntu 14.04. After installing Android Studio, I started getting this error. After all possible updates it still din't work. I had become crazy in solving this issue.                             After executing this command this error got resolved. First Command : adb apt-get install lib32stdc++6  Second Command : sudo apt-get install lib32z1 For other Adb related issue  

A Complete Nodejs boiler plate - This man need no introduction

Node.js  is an open-source, cross-platform JavaScript run-time environment that executes JavaScript code outside of a browser. A highly used solution in current mobile and cloud environment. Node.js allows the creation of  Web servers  and networking tools using  JavaScript  and a collection of "modules" that handle various core functionality. Modules are provided for  file system  I/O, networking ( DNS ,  HTTP ,  TCP ,  TLS/SSL , or  UDP ),  binary  data (buffers),  cryptography  functions,  data streams , and other core functions. Node.js's modules use an API designed to reduce the complexity of writing server applications. Nodejs is a powerful platform. Its being used across multiple applications.  Looking at the usability of Nodejs I have created a nodejs boilter plate for beginners and professionals. You can plugin play your required features. This...