Go The difference between intent and pendingintent

Source: Internet
Author: User

Intent English means intention, pending means something that is about to happen or come. Pendingintent This class is used to handle what is about to happen. For example, in the notification notification for the jump page, but not immediately jump.
Intent is started in time and Intent disappears as the activity disappears. Pendingintent can be seen as intent packaging, usually through Getactivity,getbroadcast, getservice to get pendingintent instances, The current activity does not immediately start the intent it contains, but instead calls the intent when the pendingintent is executed externally. Because the context of the current app is saved in the pendingintent, it gives the external app the ability to execute the Intent in the pendingintent like the current app, even if the current app doesn't exist at the time of execution. Intent can also be executed through the presence of the context in the pendingintent. You can also handle the operations after intent execution. Often used with Alermanger and Notificationmanager. Intent is generally used to transfer data between activity, Sercvice, Broadcastreceiver, and pendingintent, generally used on notification, can be understood as the intent of deferred execution, Pendingintent is a wrapper over intent.

Java code
  1. Private void shownotify () {
  2. Notification notice=new Notification ();
  3. Notice.icon=r.drawable.icon;
  4. notice.tickertext="You have a new piece of information";
  5. Notice.defaults=notification.default_sound;
  6. notice.when=10l;
  7. //100 ms Delay, shock 250 ms, pause 100 milliseconds, then shake 500 milliseconds
  8. //notice.vibrate = new long[] {100, 250, 100, 500}; error?
  9. //notice.setlatesteventinfo (This, "notice", "Meeting", Pendingintent.getactivity (this, 0, NULL, 0));
  10. Notice.setlatesteventinfo (This, "notice", "Meeting", Pendingintent.getactivity (this, 0, new Intent (this, Activity2. class), 0)); //will jump to the page, not yet jump
  11. Notificationmanager manager= (Notificationmanager) getsystemservice (this. Notification_service);
  12. Manager.notify (0,notice);
  13. }
[Java]View Plaincopyprint?
  1. Private void Shownotify () {
  2. Notification notice=New Notification ();
  3. Notice.icon=r.drawable.icon;
  4. notice.tickertext="You have a new piece of information";
  5. Notice.defaults=notification.default_sound;
  6. notice.when=10l;
  7. //100 ms Delay, shock 250 ms, pause 100 milliseconds, then shake 500 milliseconds
  8. //notice.vibrate = new long[] {100, 250, 100, 500}; error?
  9. //notice.setlatesteventinfo (This, "notice", "Meeting", Pendingintent.getactivity (this, 0, NULL, 0));
  10. Notice.setlatesteventinfo (This, "notice", "Meeting", pendingintent.getactivity (this, 0, new Intent ( This,activity2. Class), 0)); //will jump to the page, not yet jump
  11. Notificationmanager manager= (Notificationmanager) Getsystemservice (this.  Notification_service);
  12. Manager.notify (0,notice);
  13. }
private void Shownotify () {    Notification notice=new Notification ();    Notice.icon=r.drawable.icon;    Notice.tickertext= "You have a new piece of information";    Notice.defaults=notification.default_sound;    notice.when=10l;    100 ms delay, vibration 250 ms, pause 100 milliseconds, then shake 500 milliseconds      //notice.vibrate = new long[] {100, 250, 100, 500}; error?    //notice.setlatesteventinfo (This, "notice", "Meeting", Pendingintent.getactivity (this, 0, NULL, 0)); Notice.setlatesteventinfo (This, "notice", "Meeting", Pendingintent.getactivity (this, 0, new Intent (This,activity2.class), 0)) ;//will jump to the page, has not jumped    Notificationmanager manager= (Notificationmanager) Getsystemservice (this. Notification_service);    Manager.notify (0,notice);    }

1. Example of sending SMS to Android in GSM network

Java code
    1. String msg ="Hello, beauty";
    2. String number = "135****6784";
    3. Smsmanager SMS = Smsmanager.getdefault ();
    4. pendingintent pi = pendingintent.getbroadcast (smsactivity.   This,0,new Intent (...),0);
    5. Sms.sendtextmessage (number, null, MSG, pi, null);
    6. Toast.maketext (smsactivity.   This,"Send Success", Toast.lenght_long). Show ();
[Java]View Plaincopyprint?
    1. string msg = "Hello, beauty";   
    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, "send Success", Toast.lenght_long). Show ();   
string msg = "Hello, beauty"; String number = "135****6784"; Smsmanager SMS = Smsmanager.getdefault (); pendingintent pi = pendingintent.getbroadcast (smsactivity.this,0,new Intent (...), 0); Sms.sendtextmessage (number, NULL, MSG, PI, null); Toast.maketext (Smsactivity.this, "Send Success", Toast.lenght_long). Show (); 

Code explanation pendingintent is a description of the intent, we can give this description to other programs, other programs according to this description at a later time to do what you do (by the giving a pendingintent to another app Lication, you were granting it the right to perform the operation you had specified as if the other application was Yourse LF, the equivalent of pendingintent represents intent).       In this case, the other program is to send a text message program, SMS sent after the success of the intent broadcast out. function Smsmanager.sendtextmessage (string destinationaddress, String scaddress, string text, Pendingintent sentintent, Pendingintent deliveryintent) Parameter explanation: 1) pendingintent sentintent: When the text message is sent, the successful sendintent will broadcast the intent of its internal description, Otherwise, the error code is generated and the callback through android.app.PendingIntent.OnFinished, this parameter is best not empty, otherwise there will be a potential problem of resource wasting; 2) pendingintent       Deliveryintent: A pendingintent broadcast that is carried out when a message has been delivered to the addressee. Looking at the Pendingintent class, you can see many of the send functions, that is, Pendingintent is doing the related operations that are assigned.

Go The difference between intent and pendingintent

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.