PendingIntent和Intent的区别
来源:互联网 发布:linux清除arp缓存 编辑:程序博客网 时间:2024/05/06 05:39
- Notification n = new Notification(R.drawable.face_1, "Service启动", System.currentTimeMillis());
- PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, TServiceHolder.class), 0);
- n.setLatestEventInfo(this, "任务标题", "任务内容", contentIntent);
- nManager.notify(NOTIFICATION_ID, n); // 任务栏启动
PendingIntent和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. GSM网络中android发送短信示例
(1)代码节选
- String msg ="你好,美女";
- 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,"发送成功",Toast.LENGHT_LONG).show();
(2)代码解释
PendingIntent就是一个Intent的描述,我们可以把这个描述交给别的程序,别的程序根据这个描述在后面的别的时间做你安排做的事情 (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,就相当于PendingIntent代表了Intent)。本例中别的程序就是发送短信的程序,短信发送成功后要把intent广播出去 。
函数SmsManager.sendTextMessage(String destinationAddress, String scAddress, String text, PendingIntent sentIntent, PendingIntent deliveryIntent)中参数解释:
1)PendingIntent sentIntent:当短信发出时,成功的话sendIntent会把其内部的描述的intent广播出去,否则产生错误代码并通过android.app.PendingIntent.OnFinished进行回调,这个参数最好不为空,否则会存在资源浪费的潜在问题;
2)PendingIntent deliveryIntent:是当消息已经传递给收信人后所进行的PendingIntent广播。
查看PendingIntent 类可以看到许多的Send函数,就是PendingIntent在进行被赋予的相关的操作。
总结:
Intent 表示一个目的,第一个参数表示所在类,第二个参数表示目标类PendingIntent 即是一个Intent的描述
PendingIntent和Intent的区别:
PendingIntent就是一个Intent的描述,我们可以把这个描述交给别的程序,别的程序根据这个描述在后面的别的时间做你安排做的事情
换种说法Intent 字面意思是意图,即我们的目的,我们想要做的事情,在activity中,我们可以立即执行它
PendingIntent 相当于对intent执行了包装,我们不一定一定要马上执行它,我们将其包装后,传递给其他activity或application
这时,获取到PendingIntent 的application 能够根据里面的intent 来得知发出者的意图,选择拦击或者继续传递或者执行.
- Intent和PendingIntent的区别
- PendingIntent和Intent的区别
- Intent和PendingIntent的区别
- Intent和PendingIntent的区别
- PendingIntent和Intent的区别
- PendingIntent和Intent的区别
- Intent和PendingIntent的区别
- Intent和PendingIntent的区别
- Intent和PendingIntent的区别
- PendingIntent和Intent的区别
- Intent和PendingIntent的区别
- Intent和PendingIntent的区别
- Intent和PendingIntent的区别
- Intent和PendingIntent的区别
- Intent和PendingIntent的区别
- Intent和PendingIntent的区别
- Intent和PendingIntent的区别
- Intent和PendingIntent的区别
- 从e看中国数学教育
- 佛罗里达州的最新的野生动物保护区
- 一个字符串的调试问题
- 数据库(第一范式,第二范式,第三范式)
- 软件易用性测试
- PendingIntent和Intent的区别
- C标准I/O库
- 2012年继续学习一天一小时
- Eclipse安装DSS会出现的一点问题
- InstallShield安装包中集成第三方安装包的方案选择
- 24个足以改变事业的商业妙想
- 解酒方法10种
- WinPcap文档翻译之《Filtering expression syntax》
- 启动Android模拟器报 PANIC: Could not open /.android/avd/test.ini 问题解决