The difference between "Android app development" 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. Just because of pendingintent

Has the context of the current app, giving it the ability to give an external app a way to execute pendingintent like the current app

Intent, even in the execution of the current app does not exist, but also through the presence of pendingintent in the context of the same execution Intent. Alternatively, you can

Handles the operation after the intent executes. 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 deferred execution of the intent, Pendingintent is a wrapper over intent.

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

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

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

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 the other time to do what you do (by giving a pendingintent to another Application, you is granting it the right to perform the operation you has specified as if the other application is you Rself, 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) in the parameter explanation:
1) pendingintent Sentintent: When the text message is issued, the success of Sendintent will be the description of its internal intent broadcast out, Otherwise, the error code and through the android.app.PendingIntent.OnFinished callback, this parameter is best not empty, otherwise there will be a potential problem of resource waste;
2) Pendingintent deliveryintent: is a pendingintent broadcast when the 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.

The difference between "Android app development" intent and Pendingintent

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.