FileDocCategorySizeDatePackage
IntentService.javaAPI DocAndroid 1.5 API2109Wed May 06 22:41:54 BST 2009android.app

IntentService

public abstract class IntentService extends Service
An abstract {@link 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 {@link #onHandleIntent}. The {@link Service} will automatically be stopped when the last enqueued {@link Intent} is handled.

Fields Summary
private volatile android.os.Looper
mServiceLooper
private volatile ServiceHandler
mServiceHandler
private String
mName
Constructors Summary
public IntentService(String name)

        super();
        mName = name;
    
Methods Summary
public android.os.IBinderonBind(android.content.Intent intent)

        return null;
    
public voidonCreate()

        super.onCreate();
        HandlerThread thread = new HandlerThread("IntentService[" + mName + "]");
        thread.start();

        mServiceLooper = thread.getLooper();
        mServiceHandler = new ServiceHandler(mServiceLooper);
    
public voidonDestroy()

        mServiceLooper.quit();
    
protected abstract voidonHandleIntent(android.content.Intent intent)
Invoked on the Handler thread with the {@link Intent} that is passed to {@link #onStart}. Note that this will be invoked from a different thread than the one that handles the {@link #onStart} call.

public voidonStart(android.content.Intent intent, int startId)

        super.onStart(intent, startId);
        Message msg = mServiceHandler.obtainMessage();
        msg.arg1 = startId;
        msg.obj = intent;
        mServiceHandler.sendMessage(msg);