Differences between pendingintent and intent

Source: Internet
Author: User

An intent is something that is used right now; A pendingintent is something that may create an intent in the future. You will use a pendingintent with notifications, alarmmanager, etc.

Notification n = new notification (R. drawable. face_1, "Service Startup", system. currenttimemillis (); pendingintent contentintent = pendingintent. getactivity (this, 0, new intent (this, tserviceholder. class), 0); N. setlatesteventinfo (this, "task title", "task content", contentintent); nmanager. Y (ication_id _id, n); // start the taskbar

 

String MSG = "Hello, beautiful girl"; string number = "187 *** 5477"; smsmanager SMS = smsmanager. getdefault (); pendingintent Pi = pendingintent. getbroadcast (smsactivity. this, 0, new intent (...), 0); SMS. sendtextmessage (number, null, MSG, PI, null); // broadcast intent to toast after the message is sent successfully. maketext (smsactivity. this, "sent successfully", toast. lenght_long ). show ();

 

By giving a pendingintent to another application, you are granting it the right to perform the operation you have specified as if the other application was yourself, it is equivalent to pendingintent representing the intent

Description of parameters in the smsmanager. sendtextmessage (string destinationaddress, string scaddress, string text, pendingintent sentintent, pendingintent deliveryintent) function:

1) pendingintent sentintent: if the message is sent successfully, sendintent broadcasts the intent of its internal description. Otherwise, an error code is generated and sent to Android. app. pendingintent. onfinished callback. It is best not to leave this parameter blank, otherwise there may be potential problems of resource waste;

2) pendingintent deliveryintent: The pendingintent broadcast that is performed after the message has been delivered to the recipient.

View the pendingintent class. You can see many send functions, that is, pendingintent is performing related operations.

 

========================================================== ==============================================

Intent indicates a purpose, the first parameter indicates the class, and the second parameter indicates the target class.

Pendingintent is the description of an intent.

Differences between pendingintent and intent:

Pendingintent is an intent description. We can give this description to another program. Other programs will do what you want to do at the rest of the time according to this description.

Intent literally means intent, that is, our purpose. What we want to do can be executed immediately in activity.

Pendingintent is equivalent to packaging intent. We don't have to execute it immediately. We wrap it and pass it to another activity or application.

At this time, the pendingintent application can be obtained based on the intent to learn the intent of the sender, choose to block or continue to pass or execute

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.