Android Tutorial

(avery) #1
Android Tutorial 417

This is displayed to the user as a small number over the icon. This
is only displayed in the status bar and not in the expanded status
bar, although an application could update the text to also display
this information. Figure shows what this might look like in the
status bar.

Status bar notification with the count of “4” showing over
the icon.

Clearing Notifications

When a user clicks on the notification, the
Intent assigned is triggered. At some
point after this, the application might
want to clear the notification from the
system notifications queue. This is done
through a call to the cancel() method of
the NotificationManager object. For
instance, the notification we created
earlier could be canceled with the
following call:

notifier.cancel(NOTIFY_1);


This cancels the notification that has the same identifier. However,
if the application doesn’t care what the user does after clicking on
the notification, there is an easier way to cancel notifications.
Simply set a flag to do so, as shown here:

notify.flags |= Notification.FLAG_AUTO_CANCEL;

Free download pdf