RemoteService.javaAPI DocAndroid 1.5 API6760Wed May 06 22:41:08 BST


public class RemoteService extends
This is an example of implementing an application service that runs in a different process than the application. Because it can be in another process, we must use IPC to interact with it. The {@link RemoteServiceController} and {@link RemoteServiceBinding} classes show how to interact with the service.

Fields Summary
final android.os.RemoteCallbackList
This is a list of callbacks that have been registered with the service. Note that this is package scoped (instead of private) so that it can be accessed more efficiently from inner classes.
private final IRemoteService.Stub
The IRemoteInterface is defined through IDL
private final ISecondary.Stub
A secondary interface to the service.
private static final int
private final android.os.Handler
Our Handler used to execute operations on the main thread. This is used to schedule increments of our value.
Constructors Summary
Methods Summary
public android.os.IBinderonBind(android.content.Intent intent)

        // Select the interface to return.  If your service only implements
        // a single interface, you can just return it here without checking
        // the Intent.
        if (IRemoteService.class.getName().equals(intent.getAction())) {
            return mBinder;
        if (ISecondary.class.getName().equals(intent.getAction())) {
            return mSecondaryBinder;
        return null;
public voidonCreate()

        mNM = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);

        // Display a notification about us starting.
        // While this service is running, it will continually increment a
        // number.  Send the first message that is used to perform the
        // increment.
public voidonDestroy()

        // Cancel the persistent notification.

        // Tell the user we stopped.
        Toast.makeText(this, R.string.remote_service_stopped, Toast.LENGTH_SHORT).show();
        // Unregister all callbacks.
        // Remove the next pending message to increment the counter, stopping
        // the increment loop.
private voidshowNotification()
Show a notification while this service is running.

        // In this sample, we'll use the same text for the ticker and the expanded notification
        CharSequence text = getText(R.string.remote_service_started);

        // Set the icon, scrolling text and timestamp
        Notification notification = new Notification(R.drawable.stat_sample, text,

        // The PendingIntent to launch our activity if the user selects this notification
        PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
                new Intent(this, LocalServiceController.class), 0);

        // Set the info for the views that show in the notification panel.
        notification.setLatestEventInfo(this, getText(R.string.remote_service_label),
                       text, contentIntent);

        // Send the notification.
        // We use a string id because it is a unique number.  We use it later to cancel.
        mNM.notify(R.string.remote_service_started, notification);