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

Native Vs Phone gap, What to use and when and why?

Well,  Currently there are millions  of application available in app stores. In that  I would say ~10% of application are based on phone gap, remaining are native. Looking at the application requirement  and the time slice available for you have to bring it in market, you should decide what to choose. So, When you must choose only native development? If your application requires access to SYSTEM APIs, in that case its compulsory to use native. If you want to access of Bluetooth, file operations, storage,  running some background operations, accessing of AT commands, communications with hardware components such as LED, navigation buttons etc. If you are building  heavy games, running algorithms to do signal processing , image processing any such heavy operations These are some of the glimpse of task, where you must use native. Phone gap will never ever will be able to give you support of proper libraries for any of these. Now, It comes to Phone gap application developme

Building Phone Gap App for Windows Phone 8

Before you start  developing an phone gap based App you need to keep following things in your mind. General Practice: Set any controls height and width always in term of percentage. Same should be applied with Div. Don't use margin at all. Use margin only to give spacing with controls- 5 px - 20 px Design a parent page.Only this page should contain head and body tag. Other layout should only contain div. After that only Remove and Append Div based on the required layout. Use boot strap to provide a web-responsive feature to your application Above practice will help you building a nice android and IOS application. but in-case of windows application same application won't work as it is. Things to take care in Phone Gap based Application. All append function will start throwing security Exceptions Use the following tag around your append code. MSApp.execUnsafeLocalFunction( function () { var body = document.getElementsByTagName( 'body' )[0]; body