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
- 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, shock 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, not yet jump
- Notificationmanager manager= (Notificationmanager) getsystemservice (this. Notification_service);
- Manager.notify (0,notice);
- }
[Java]View Plaincopy
- 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, shock 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, not yet jump
- Notificationmanager manager= (Notificationmanager) Getsystemservice (this. Notification_service);
- Manager.notify (0,notice);
- }
1. Example of sending SMS to Android in GSM network
Java code
- 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 ();
[Java]View Plaincopy
- 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 intent and pendingintent