Android development notification

Source: Internet
Author: User

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); 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.