To create and display a notification:
1. Get a icationicationmanager object through the getsystemservice Method
-- Icationicationmanager = (notificationmanager) getsystemmanager (icationication_service );
2. Create a notification object. Each notification corresponds to a notification object. In this step, you need to set the notification information displayed at the top of the screen, the image resource ID in front of the notification message, and the time when the notification is sent, which is generally the current time.
-- Notification = new notification (R. drawable. Icon, "you have new information", system. currenttimemillis ());
3. Notification can be detached from the application. That is to say, even if the application is closed, the notification will be displayed in the status bar. After the program starts, you can re-control these notifications, such as clear or replace them. Therefore, you must create a pendingintent object. This object is maintained by the Android system. Therefore, after the application is closed, the object cannot be released.
-- Pendingintent contentintent = getactivity (this, 0, getintent (), 0 );
4. Use the setlateseventinfo method of the notification class to set notification details.
Notificatio. setlateseventinfo (this, "Weather Forecast", "Clear to cloudy", contentintent );
5. Use the y icationmanager class's notify y method to display notification information. In this example, you must specify the unique ID that identifies notification. This ID must be unique relative to the same notificationmanager object. Otherwise, the same notification will be overwritten.
-- Icationicationmanager. Y (R. drawable. Icon, notification );