Differences between intent and pendingintent in Android

Source: Internet
Author: User

From: http://blog.csdn.net/xuzhuang2008/archive/2011/04/13/6321477.aspx

 

Java code
1. Notification n = new notification (R. drawable. face_1, "service started", system. currenttimemillis ());
2. pendingintent contentintent = pendingintent. getactivity (this, 0, new intent (this, tserviceholder. Class), 0 );
3. N. setlatesteventinfo (this, "task title", "task content", contentintent );
4. nmanager. Y (icationication_id, n); // start the taskbar
Differences between pendingintent and intent: 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.

 

1. Example of Android text message sending in GSM network

(1) code excerpt

Java code
1. String MSG = "Hello, beautiful girl ";
2. String number = "135 *** 6784 ";
3. smsmanager SMS = smsmanager. getdefault ();
4.
5. pendingintent Pi = pendingintent. getbroadcast (smsactivity. This, 0, new intent (...), 0 );
6. SMS. sendtextmessage (number, null, MSG, PI, null );
7. Toast. maketext (smsactivity. This, "sent successfully", Toast. lenght_long). Show ();
(2) code explanation

Pendingintent is an intent description. We can give this description to other programs, other programs will do what you want to do at the rest of the time according to this description (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 ). In this example, other programs send text messages. After the messages are sent successfully, intent should be broadcast.
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.

This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/xuzhuang2008/archive/2011/04/13/6321477.aspx

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.