public abstract class

IntentService

extends Service
java.lang.Object
   ↳ android.content.Context
     ↳ android.content.ContextWrapper
       ↳ android.app.Service
         ↳ android.app.IntentService

Class Overview

An abstract Service that serializes the handling of the Intents passed upon service start and handles them on a handler thread.

To use this class extend it and implement onHandleIntent(Intent). The Service will automatically be stopped when the last enqueued Intent is handled.

Summary

[Expand]
Inherited Constants
From class android.content.Context
Public Constructors
IntentService(String name)
Public Methods
IBinder onBind(Intent intent)
Return the communication channel to the service.
void onCreate()
Called by the system when the service is first created.
void onDestroy()
Called by the system to notify a Service that it is no longer used and is being removed.
void onStart(Intent intent, int startId)
Called by the system every time a client explicitly starts the service by calling startService(Intent), providing the arguments it supplied and a unique integer token representing the start request.
Protected Methods
abstract void onHandleIntent(Intent intent)
Invoked on the Handler thread with the Intent that is passed to onStart(Intent, int).
[Expand]
Inherited Methods
From class android.app.Service
From class android.content.ContextWrapper
From class android.content.Context
From class java.lang.Object
From interface android.content.ComponentCallbacks

Public Constructors

public IntentService (String name)

Public Methods

public IBinder onBind (Intent intent)

Return the communication channel to the service. May return null if clients can not bind to the service. The returned IBinder is usually for a complex interface that has been described using aidl.

Note that unlike other application components, calls on to the IBinder interface returned here may not happen on the main thread of the process. More information about this can be found in Application Fundamentals: Processes and Threads.

Parameters
intent The Intent that was used to bind to this service, as given to Context.bindService. Note that any extras that were included with the Intent at that point will not be seen here.
Returns
  • Return an IBinder through which clients can call on to the service.

public void onCreate ()

Called by the system when the service is first created. Do not call this method directly.

public void onDestroy ()

Called by the system to notify a Service that it is no longer used and is being removed. The service should clean up an resources it holds (threads, registered receivers, etc) at this point. Upon return, there will be no more calls in to this Service object and it is effectively dead. Do not call this method directly.

public void onStart (Intent intent, int startId)

Called by the system every time a client explicitly starts the service by calling startService(Intent), providing the arguments it supplied and a unique integer token representing the start request. Do not call this method directly.

Parameters
intent The Intent supplied to startService(Intent), as given.
startId A unique integer representing this specific request to start. Use with stopSelfResult(int).

Protected Methods

protected abstract void onHandleIntent (Intent intent)

Invoked on the Handler thread with the Intent that is passed to onStart(Intent, int). Note that this will be invoked from a different thread than the one that handles the onStart(Intent, int) call.