Notification is the status bar notification. Application Scenario: When an application does not exit but runs in the background or is concealed by other programs, such as when the program is running and the user clicks the Home key, the program does not actually exit. In this case, the running program is displayed on the status bar. When you click the program, the running interface is displayed. Notification can also be used to notify users of Program-related messages.
Let's take a look at the usage of notification. You can create a method in activity to create notification:
Private void shownotification () {// define notification manager notification_servicenotificationmanager notificationmanager = (icationicationmanager) getsystemservice (Android. content. context. notification_service); // defines the system Notification = new notification (R. drawable. icon, "Hyun Bi Feng", system. currenttimemillis (); notification. flags | = notification. flag_ongoing_event; notification. flags | = notification. flag_no_clear; notification. flags | = notification. flag_show_lights; notification. defaults = notification. default_lights; notification. ledargb = color. blue; notification. ledonms = 5000; charsequence contenttitle = "Android phone wallpaper -- Hyun Bi Feng"; charsequence contenttext = "welcome to use Hyun Bi Feng"; intent icationicationintent = new intent (); notificationintent. setcomponent (getcomponentname (); icationicationintent. setflags (intent. flag_activity_new_task); icationicationintent. setclass (context, xbfacti.pdf. class); pendingintent contentintent = pendingintent. getactivity (this, 0, icationicationintent, 0); notification. setlatesteventinfo (this, contenttitle, contenttext, contentintent); icationicationmanager. Y (0, notification );}
Then you can call this method as needed. Another problem is that when you click the icon in the status bar, a new activity will be created, instead of returning to the original activity. The solution is in androidmanifest. add the Android: launchmode = "singletask" attribute to the activity in XML.
Delete notification:
NotificationManager notificationManager = (NotificationManager) this .getSystemService(NOTIFICATION_SERVICE); notificationManager.cancel(0);