Intent和PendingIntent的区别
intent英文意思是意图,pending表示即将发生或来临的事情。
PendingIntent这个类用于处理即将发生的事情。比如在通知Notification中用于跳转页面,但不是马上跳转。
Intent 是及时启动,intent 随所在的activity 消失而消失。
PendingIntent 可以看作是对intent的包装,通常通过getActivity,getBroadcast ,getService来得到pendingintent的实例,当前activity并不能马上启动它所包含的intent,而是在外部执行 pendingintent时,调用intent的。正由于pendingintent中 保存有当前App的Context,使它赋予外部App一种能力,使得外部App可以如同当前App一样的执行pendingintent里的 Intent, 就算在执行时当前App已经不存在了,也能通过存在pendingintent里的Context照样执行Intent。另外还可以处理intent执行后的操作。常和alermanger 和notificationmanager一起使用。
Intent一般是用作Activity、Sercvice、BroadcastReceiver之间传递数据,而Pendingintent,一般用在 Notification上,可以理解为延迟执行的intent,PendingIntent是对Intent一个包装。
- private void showNotify(){
- Notification notice=new Notification();
- notice.icon=R.drawable.icon;
- notice.tickerText="您有一条新的信息";
- notice.defaults=Notification.DEFAULT_SOUND;
- notice.when=10L;
- // 100 毫秒延迟后,震动 250 毫秒,暂停 100 毫秒后,再震动 500 毫秒
- //notice.vibrate = new long[] { 100, 250, 100, 500 };出错?
- //notice.setLatestEventInfo(this, "通知", "开会啦", PendingIntent.getActivity(this, 0, null, 0));
- notice.setLatestEventInfo(this, "通知", "开会啦", PendingIntent.getActivity(this, 0, new Intent(this,Activity2.class), 0));//即将跳转页面,还没跳转
- 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="您有一条新的信息";
- notice.defaults=Notification.DEFAULT_SOUND;
- notice.when=10L;
- // 100 毫秒延迟后,震动 250 毫秒,暂停 100 毫秒后,再震动 500 毫秒
- //notice.vibrate = new long[] { 100, 250, 100, 500 };出错?
- //notice.setLatestEventInfo(this, "通知", "开会啦", PendingIntent.getActivity(this, 0, null, 0));
- notice.setLatestEventInfo(this, "通知", "开会啦", PendingIntent.getActivity(this, 0, new Intent(this,Activity2.class), 0));//即将跳转页面,还没跳转
- NotificationManager manager=(NotificationManager)getSystemService(this.NOTIFICATION_SERVICE);
- manager.notify(0,notice);
- }
1. GSM网络中android发送短信示例
- 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();
- 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();
代码解释
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在进行被赋予的相关的操作。
本文转自http://blog.csdn.net/zeng622peng/article/details/6180190
Intent和PendingIntent的区别相关推荐
- android Intent PendingIntent的区别
含义:intent英文意思是意图,pending表示即将发生或来临的事情. PendingIntent这个类用于处理即将发生的事情.比如在通知Notification中用于跳转页面,但不是马上跳转. ...
- 面试题 : Intent、IntentFilter、PendingIntent的区别
第一次写博客,有什么错误或不足的地方,请各位前辈指正. Intent:负责界面的跳转,以及数据的传递. IntentFilter:是在权限文件里面配置的一个权限,它有几种类型 PendingInten ...
- Android安全笔记-Intent和PendingIntent基本概念
Intent Intent:应用传递消息的结构体: ·通知浏览器打开一个网页: ·同志通话拨打某个号码: ·启动activity: ·启动service: ·发出broadcast. Intent包含 ...
- Intent和Bundle的区别
安卓 Intent (1)数据传递 Intent和Bundle详解 这几天在写android小程序的时候碰到了bundle,突然发现还不清楚intent和bundle之间的关系,决定百度google之 ...
- PendingIntent详解
PendingIntent描述了一个Intent和目标action.这个类的实例是用getActivity(Context,int,Intent,int)方法和getBroadcast(Context ...
- Android中pendingIntent的深入理解
pendingIntent字面意义:等待的,未决定的Intent. 要得到一个pendingIntent对象,使用方法类的静态方法 getActivity(Context, int, Intent, ...
- [转]Android中pendingIntent的深入理解
转自;here pendingIntent字面意义:等待的,未决定的Intent. 要得到一个pendingIntent对象,使用方法类的静态方法 getActivity(Context, int, ...
- AlarmManager与PendingIntent
1.AlarmManager的作用与PendingIntent的关系 顾名思义,就是"提醒",是Android中常用的一种系统级别的提示服务,在特定的时刻为我们广播一个指定的Int ...
- Android中的Notification
原帖地址:http://www.cnblogs.com/newcj/archive/2011/03/14/1983782.html Notification 的使用需要导入 3 个类 1 2 3 im ...
最新文章
- 银行持续交付实战:一个单体系统足以撑起全球大项目
- 语音中的 Transformer一文打尽!
- 利用FFT计算非平稳随机信号WVD分布
- 如何使用Appverifier ?
- Tomcat NIO
- 前端学习(1166):扩展运算符02
- Linux FTP服务配置
- Pandas 通用方法
- markdown不允许还有人不会
- 【转载】Android编译系统Makefile(Android.mk)写法
- python高斯求和_利用Python进行数据分析(3)- 列表、元组、字典、集合
- 【进阶3-4期】深度解析bind原理、使用场景及模拟实现
- sklearn,SVM 和文本分类
- web安全的一些专业术语介绍
- 记一个藏得很深的bug
- ESP8266-Arduino编程实例-SHT40温湿度传感器驱动
- 微信JS-SDK说明文档 能调用微信扫一扫 ,那能不能让浏览器支持微信支付呢
- Error:(3, 50) java: 程序包com.n.c.caa.cds.commons.constants不存在
- 基于大数据的能力开放平台解决方案
- ViveInputUtility-手柄拾取3D物体(7)
热门文章
- IJCAI 2021 医药AI必读论文推荐
- 最近发现的一些Python写程序的小技巧
- java calendar与date_java---Calendar与Date
- java交通工具的类继承代码_Java作业-交通工具继承
- UpSetR 高级参数使用教程
- 港大徐爱民组研究助理招聘-内分泌代谢方向
- ISME:水库蓝藻影响真核浮游生物的群落演替和物种共存
- Microbiome: 绝对定量环境样本细菌、真菌、真核群落丰度
- R语言可视化:散点图、散点图和折线图(line charts)、3D散点图、旋转3D散点图、气泡图、corrgram包可视化相关性矩阵、马赛克图( Mosaic plots)、hexbin、密度图
- 什么是回归分析(regression analysis)?有哪些类型的回归分析(regression analysis)?