O'Reilly logo

Android™ Tablet Application Development For Dummies® by Donn Felker

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Clearing a Notification

Users are highly unpredictable — they could be anyone, anywhere in the world! They could be first-time users, advanced power users, and so on. Each user uses the device in his or her own special way, including ways you may not predict. Case in point: What happens if your user sees a notification and decides to open the app the manual/long way — via the app launcher?

If the user decides to open your application via the app launcher while a notification is active, your notification will persist. Even if the user looks at the task at hand, the notification will still persist on the status bar. Although this is not a big deal, your application should be able to recognize the state of the application and should take the appropriate measures to cancel any existing notifications that might be present for the given task. However, if the user opens your app and reviews a different task that does not have an active notification, you should not clear any notifications. Only clear the notification for tasks that the user is reviewing.

With the cancel() method, the NotificationManager makes it simple to cancel an existing notification. The cancel() method accepts one parameter — the ID of the notification. Remember how you used the ID of the task as the ID for the note? This is why you did that. The ID of the task is unique to the Task Reminder application. By doing this, you can easily open a task and cancel any existing notification by calling the cancel() method with ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required