Learn about android-Notification

Source: Internet
Author: User

Learn about android-Notification
Notification can be understood as the meaning of the Notification and will appear in the Notification bar. For example, there are three steps to use Notification in a text message: 1. create the icationicationmanager object 2. set attributes for Notification 3. use icationicationmanager's notify to send a notification instance: send a notification copy code 1/** 2 * Create notify 3 */4 private void createnoworkflow () {5 // create icationicationmanager object 6 icationicationmanager manager = (icationicationmanager) getSystemService (NOTIFICATION_SERVICE); 7 // create yycation object 8 Notification notify = new Notification (); 9 Every y. icon = R. drawable. icon_reply; // set the icon to 10 y. when = System. currentTimeMillis (); // The time when the notification is sent. 11 notify. tickerText = "hi, I'm Coming"; // The prompt text is 12 y. flags = Notification. FLAG_AUTO_CANCEL; // automatically cancels 13 Intent intent = new Intent (this, NextActivity. class); 14 PendingIntent pIntent = PendingIntent. getActivity (this, 0, intent, 15 PendingIntent. FLAG_UPDATE_CURRENT); 16 Y. setLatestEvent Info (this, "coming to message", "one notification", pIntent); 17 manager. Y (10, notify); // send a notification, 10 is the id18} of the notification. Copy the Code. This method can be set to call in the event of a button. After running the program, click the button to see that the notification is sent. Layout files and related code are not written here. PendingIntent is the Intent package. Here is the description of the startup Intent. The PendingIntent returned by PendingIntent. getActivity indicates that the Intent in this PendingIntent instance is the Intent used to start the Activity. The parameters of PendingIntent. getActivity are Context, and the request code of the sender (0 can be entered) is used for the Intent sent by the system. PendingIntent. FLAG_UPDATE_CURRENT indicates that if the PendingIntent of the description already exists, the Extra data of the existing PendingIntent is changed to the Extra data of the new PendingIntent. The difference between Intent and PendingIntent: Intent: tells the system what I want to do, and then the system does the corresponding thing according to this Intent. For example, startActivity is equivalent to sending a message, while Intent is the content of the message. PendingIntent: Wrap Intent. Intent is our intention to start a job directly using startActivity, startService or sendBroadcast. In some cases, we cannot directly call startActivity, startServide, or sendBroadcast, but send Intent only when the program or system reaches a certain condition. For example, after you click Notification, the system sends an Intent of the Activity. Therefore, if we do not need to tell the system in some way, the system does not know whether to use startActivity, startService or sendBroadcast to start Intent (of course there are other "descriptions "), therefore, PendingIntent is required here.

Related Article

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.