NotifyingService.javaAPI DocAndroid 1.5 API5005Wed May 06 22:41:08 BST


public class NotifyingService extends
This is an example of service that will update its status bar balloon every 5 seconds for a minute.

Fields Summary
private static int
private android.os.ConditionVariable
private Runnable
private final android.os.IBinder
Constructors Summary
Methods Summary
public android.os.IBinderonBind(android.content.Intent intent)

        return mBinder;
public voidonCreate()

        mNM = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

        // Start up the thread running the service.  Note that we create a
        // separate thread because the service normally runs in the process's
        // main thread, which we don't want to block.
        Thread notifyingThread = new Thread(null, mTask, "NotifyingService");
        mCondition = new ConditionVariable(false);
public voidonDestroy()

        // Cancel the persistent notification.
        // Stop the thread from generating further notifications;
private voidshowNotification(int moodId, int textId)

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

        // Set the icon, scrolling text and timestamp.
        // Note that in this example, we pass null for tickerText.  We update the icon enough that
        // it is distracting to show the ticker text every time it changes.  We strongly suggest
        // that you do this as well.  (Think of of the "New hardware found" or "Network connection
        // changed" messages that always pop up)
        Notification notification = new Notification(moodId, null, System.currentTimeMillis());

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

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

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