Android Programming Tutorials

(Romina) #1
A Subtle Notification

Figure 36. The Patchy notification event information

If you tap on that event, you will be returned to Patchy, even if you had


closed out of it earlier. However, the icon will stick around, even after re-


opening Patchy, unless you manually clear it using the Clear button in the


notification drawer.


Step #4: Clearing the Notification.....................................................


What would be nice is to clear the Notification automatically once the user


clicks on it. To do this, first implement a clearNotification() method in


Patchy:


private void clearNotification() {
NotificationManager mgr=
(NotificationManager)getSystemService(NOTIFICATION_SERVICE);

mgr.cancel(PostMonitor.NOTIFICATION_ID);
}

Then, make a call to clearNotification() from onCreate():


223
Free download pdf