FileDocCategorySizeDatePackage
RemoteService.javaAPI DocGoogle Android v1.5 Example3053Sun Nov 11 13:01:04 GMT 2007com.google.android.samples.app

RemoteService

public class RemoteService extends android.app.Service
This is an example of implementing an application service that runs in a different process than the application. Note that it is no different than {@link LocalService} -- the only difference is how we describe it in AndroidManifest.xml. The {@link RemoteServiceController} and {@link RemoteServiceBinding} classes show how to interact with the service.

Fields Summary
static final int
GET_PID_TRANSACTION
This is the one call we can receive from clients.
private final IRemoteService.Stub
mBinder
The IRemoteInterface is defined through IDL
private android.app.NotificationManager
mNM
Constructors Summary
Methods Summary
public android.os.IBindergetBinder()

        return mBinder;
    
protected voidonCreate()


    
       
        mNM = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);

        // This is who should be launched if the user selects our persistent
        // notification.
        Intent intent = new Intent(this, LocalServiceController.class);

        // Display a notification about us starting.
        mNM.notifyWithText(R.string.remote_service_started,
                   getText(R.string.remote_service_started),
                   NotificationManager.LENGTH_SHORT,
                   new Notification(
                       R.drawable.stat_sample,
                       getText(R.string.remote_service_label),
                       intent,
                       null, 
                       null));
    
protected voidonDestroy()

        // Cancel the persistent notification.
        mNM.cancel(R.string.remote_service_started);

        // Tell the user we stopped.
        mNM.notifyWithText(R.string.remote_service_stopped,
                   getText(R.string.remote_service_stopped),
                   NotificationManager.LENGTH_SHORT,
                   null);