A status bar notification is used to notify the user of a system event, like an sms being received or a new device being detected, without interrupting the user from whatever other task they might be doing with their phone.
The status bar area is located at the top of the screen and the user can pull this area to expand it, and show a history of notifications.
If a Notification has been setup to include an enclosed Intent, selecting that particular notification in this expanded view can fire the Intent, taking the user to an Activity screen of the related application, or do any of the many other things that Intents can do.
You can also configure the notification to alert the user with a sound, a vibration, and flashing lights on the device.
A background Service should never launch an Activity on its own in order to receive user interaction. The Service should instead create a status bar notification that will launch the Activity when selected by the user.
A status bar notification should be used for any case in which a background Service needs to alert the user about an event.
Here is a simple method that creates and displays a notification when passed a string
public void displayNotification(String msg)
NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(R.drawable.icon, msg, System.currentTimeMillis());
// The PendingIntent will launch activity if the user selects this notification
PendingIntent contentIntent = PendingIntent.getActivity(this, REQUEST_CODE, new Intent(this, ExpandNotification.class), 0);
notification.setLatestEventInfo(this, "Title here", ".. And here's some more details..", contentIntent);
.. Which you can call simply like this:
displayNotification("Hi, I'm a Statusbar Notification..");
.. Easy, isn't it?