Notifications

In this lecture, we discuss Android's notification mechanism which allows apps or services associated with an app to inform the user of an event. Android supports a number of different ways to inform the user including:

  1. Staus bar at the top of the UI, owned and managed by the Android system but apps can display messages or icon in the notification area.
  2. Play sounds, uses lights and vibrate the phone to inform the user of an app related event
  3. Notification tray or drawer which allows the app to present more information and certain control elements such as navigating back to the main app, that is, bring the app back into focus if its paused.

We will focus on the status bar notification in this lecture. You will need to implement this type of notification for MyRuns4.

What this lecture will teach you

Demo projects

The demo code used in this lecture include:

Resources

Some excellent references.

Interacting with the status bar

Typically a programmer develops an app and needs to inform the user of an event that is outside of the normal UI. For example if we consider MyRuns4 that you are coding right now. When the user starts an exercise using the GPS mode (or automatic) the code creates a service to process location updates. When this service starts on an independent thread in the background it informs the user that it is running by display first message (i.e., "MyRuns is recording your path" ) and then an icon (i.e., the D icon) in the notification area. We can see this below

To see the details of the MyRuns4 notification, the user needs to wipe down on the status bar (i.e., notification area) to open the notification drawer. The system controls the notification area and drawer and allows the user to view and interact with it at any point For example, in the case of MyRuns4 notification in the drawer the user can wipe down the status bar and click on the MyRuns notification in the drawer and it bring the app back into focus.

Notify demo app

$ keytool -list -v -keystore ~/.android/debug.keystore -alias androiddebugkey -storepass android -keypass android